Adding EF Core Interceptors when using Aspire Client Integration Packages #6967
Unanswered
mehmetozkaya
asked this question in
Q&A
Replies: 1 comment 2 replies
-
The answer is here: |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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.
While configuring AddNpgsqlDbContext with configureDbContextOptions, I noticed that the serviceProvider parameter isn’t available, which prevents me from resolving dependencies like ISaveChangesInterceptor implementations from the DI container.
In my current setup with traditional DI registration for EF Core, I rely on the serviceProvider parameter to resolve interceptors dynamically, specifically for DispatchDomainEventsInterceptor. This interceptor depends on IMediator (from MediatR) to publish domain events, making the serviceProvider crucial for resolving these dependencies.
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.
Full code example: GitHub Link
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.
All reactions