-
Couldn't load subscription status.
- Fork 131
Feature: Add EnrichSqliteDatabaseDbContext extension method for WebApplicationBuilder #837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…Builder Co-authored-by: aaronpowell <[email protected]>
Co-authored-by: aaronpowell <[email protected]>
…DbContext Co-authored-by: aaronpowell <[email protected]>
Minimum allowed line rate is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new EnrichSqliteDatabaseDbContext<TDbContext> extension method that provides a simplified API for ASP.NET Core applications to register Entity Framework Core DbContext with SQLite provider, including optional OpenTelemetry instrumentation support.
Key changes:
- New extension method targeting
IHostApplicationBuilderwith simplified parameter-based configuration - Added OpenTelemetry EF Core instrumentation support with optional disable flag
- Comprehensive unit tests covering all usage scenarios and error validation
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
AspireEFSqliteExtensions.cs |
Added new EnrichSqliteDatabaseDbContext method and refactored instrumentation configuration |
SqliteEntityFrameworkCoreSettings.cs |
Added DisableTracing property to control OpenTelemetry instrumentation |
EnrichSqliteDatabaseDbContextTests.cs |
New test file with comprehensive coverage of the new extension method |
CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite.csproj |
Added OpenTelemetry package references |
README.md |
Updated documentation with new usage examples and comparison table |
Directory.Packages.props |
Added OpenTelemetry.Instrumentation.EntityFrameworkCore package |
Directory.Build.props |
Updated OpenTelemetry version to 1.12.0 |
Comments suppressed due to low confidence (1)
src/CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite/SqliteEntityFrameworkCoreSettings.cs:1
- The comment incorrectly refers to 'PostgreSQL database' when this is a SQLite settings class. It should say 'SQLite database'.
namespace Microsoft.Extensions.Hosting;
| ]); | ||
|
|
||
| // Act | ||
| builder.EnrichSqliteDatabaseDbContext<TestDbContext>(settings => settings.DisableTracing = true); |
Copilot
AI
Sep 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test method name suggests it tests the enableOpenTelemetry parameter, but the implementation uses a settings configuration delegate instead. The method signature in the actual implementation doesn't match what's being tested here.
| ]); | ||
|
|
||
| // Act | ||
| builder.EnrichSqliteDatabaseDbContext<TestDbContext>(settings => settings.DisableTracing = false); |
Copilot
AI
Sep 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test method name suggests it tests the default OpenTelemetry behavior, but it's explicitly setting DisableTracing = false. This test should either call the method without parameters to test the actual default behavior, or rename the test to reflect what it's actually testing.
| builder.EnrichSqliteDatabaseDbContext<TestDbContext>(settings => settings.DisableTracing = false); | |
| builder.EnrichSqliteDatabaseDbContext<TestDbContext>(); |
| ); | ||
|
|
||
| configureSettings?.Invoke(settings); | ||
|
|
Copilot
AI
Sep 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The connection string is not validated before use. Unlike the existing AddSqliteDbContext method which validates the connection string, this new method directly passes settings.ConnectionString to UseSqlite without checking if it's null or empty.
| if (string.IsNullOrWhiteSpace(settings.ConnectionString)) | |
| { | |
| throw new ArgumentException("The connection string for Sqlite DbContext cannot be null or empty.", nameof(settings.ConnectionString)); | |
| } |
…plicationBuilder (CommunityToolkit#837) * Initial plan * Add EnrichSqliteDatabaseDbContext extension method for WebApplicationBuilder Co-authored-by: aaronpowell <[email protected]> * Complete EnrichSqliteDatabaseDbContext with OpenTelemetry support Co-authored-by: aaronpowell <[email protected]> * Add documentation and complete test coverage for EnrichSqliteDatabaseDbContext Co-authored-by: aaronpowell <[email protected]> * Aligning properly with the aspire implementations --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: aaronpowell <[email protected]> Co-authored-by: Aaron Powell <[email protected]>
This PR implements a new
EnrichSqliteDatabaseDbContext<TDbContext>extension method that provides a simplified API for registering Entity Framework Core DbContext with SQLite provider onWebApplicationBuilder, including built-in OpenTelemetry instrumentation support.API
Key Features
WebApplicationBuilderinstead of requiringIHostApplicationBuilderUsage Examples
Benefits
Implementation Details
Microsoft.AspNetCore.Buildernamespace for WebApplicationBuilder extensionsAddDbContextfor standard registration (vsAddDbContextPoolused by the existing method)Comparison with Existing Method
AddSqliteDbContextEnrichSqliteDatabaseDbContextIHostApplicationBuilderWebApplicationBuilderBoth methods can coexist and serve different use cases - the existing method for advanced scenarios and the new method for simplified, common use cases.
Fixes #821.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
dnceng.pkgs.visualstudio.comdotnet build /home/REDACTED/work/Aspire/Aspire/src/CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite/ --verbosity normal(dns block)dotnet msbuild src/CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite/ -p:TargetFramework=net8.0 -t:restore(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.