Adding EF Core Interceptors when using Aspire Client Integration Packages #6967
-
I’ve recently added PostgreSQL hosting integration into my AppHost project and after that included the Aspire.Npgsql.EntityFrameworkCore.PostgreSQL client integration NuGet package in my API project. Here’s a comparison of the two setups: Traditional EF Core DI Registration with Interceptors
This works perfectly as sp.GetServices() dynamically resolves my interceptors, including DispatchDomainEventsInterceptor, which depends on MediatR. Using Aspire.Npgsql.EntityFrameworkCore.PostgreSQL with AddNpgsqlDbContext
As you can see, without the serviceProvider parameter, I’m unable to dynamically resolve ISaveChangesInterceptor or inject dependencies like IMediator into my interceptors. Questions and Suggestions
I came across a related discussion here: GitHub Issue #4202, but it hasn’t been resolved yet. Any insights or updates on this topic would be immensely helpful. Thank you for your time and effort! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The answer is here: |
Beta Was this translation helpful? Give feedback.
connectionName: "x"
translates tobuilder.Configuration.GetConnectionString("x")
so it should be trivial to do the same in your code:I see the confusion here, our documentation is wrong https://learn.microsoft.com/en-us/dotnet/aspire/database/postgresql-entity-framework-integration?tabs=dotnet-cli#add-npgsql-dat…