Skip to content

Align Sqlite enrich behavior#1282

Open
DavidGarton8 wants to merge 1 commit intoCommunityToolkit:mainfrom
DavidGarton8:sqlite_enrich
Open

Align Sqlite enrich behavior#1282
DavidGarton8 wants to merge 1 commit intoCommunityToolkit:mainfrom
DavidGarton8:sqlite_enrich

Conversation

@DavidGarton8
Copy link
Copy Markdown

Closes #1269

Make EnrichSqliteDatabaseDbContext follow the Aspire enrich pattern by requiring the DbContext to already be registered instead of registering it itself.

This updates the SQLite enrichment behavior to match the expected enrich contract used elsewhere in Aspire integrations. EnrichSqliteDatabaseDbContext<TDbContext> now validates that TDbContext is already registered in DI and then applies enrichment features such as health checks, logging, retries, and telemetry.

The test suite has also been updated to reflect this behavior:

  • verifies enrichment works when the DbContext is already registered
  • verifies an InvalidOperationException is thrown when the DbContext has not been registered
  • updates telemetry-related tests to use an existing registration

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • New integration
    • Docs are written
    • Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

Other information

This is a breaking behavioral change intended to align this API with the existing Aspire enrich pattern.

EnrichSqliteDatabaseDbContext<TDbContext> previously registered the DbContext itself, but after this change it requires the DbContext to already be registered and only applies enrichment behavior.

This follows the intended Aspire enrich pattern by allowing consumers to register the DbContext however they want before applying enrichment.

This is a deliberate contract alignment change, and the impact should be limited because this method was only introduced in preview/beta packages and was not part of an official stable release.

Migration

Before:

builder.EnrichSqliteDatabaseDbContext<MyDbContext>();

After:

builder.Services.AddDbContext<MyDbContext>(options => options.UseSqlite("..."));
builder.EnrichSqliteDatabaseDbContext<MyDbContext>();

Make EnrichSqliteDatabaseDbContext follow the Aspire enrich pattern by requiring the DbContext to already be registered instead of registering it itself.

Update the tests to reflect the new contract, including coverage
for missing DbContext registration and successful enrichment of an
existing registration.
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.sh | bash -s -- 1282

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.ps1) } 1282"

@DavidGarton8
Copy link
Copy Markdown
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EnrichSqliteDatabaseDbContext registers DbContext

1 participant