Skip to content
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

Add another parameter in the AddSqlServerDbContext configureDbContextOptions to receive the scoped service provider #7020

Open
1 task done
luizfbicalho opened this issue Jan 4, 2025 · 0 comments

Comments

@luizfbicalho
Copy link

luizfbicalho commented Jan 4, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

My dbcontext has some changes in the configuration

        builder.AddSqlServerDbContext<ModelContext>("sqldb-model", configureDbContextOptions: (options) =>
        {
            options.UseLazyLoadingProxies()
                .ReplaceService<ILazyLoader, EnableDisableLazyLoader>()
                .AddInterceptors(
                    provider.GetRequiredService<ValidateSaveChangesInterceptor>(),
                    provider.GetRequiredService<ServiceLoggerSaveChangesInterceptor<ModelContext>>()
                );
        });

The original problem is that I can't add a generic AddInterceptor<ValidateSaveChangesInterceptor>() call and make my dbcontext to get the interceptor from service provider in the correct scope

Describe the solution you'd like

I would like a new method like this

 public static void AddSqlServerDbContext<[DynamicallyAccessedMembers(RequiredByEF)] TContext>(
     this IHostApplicationBuilder builder,
     string connectionName,
     Action<IServiceProvider,MicrosoftEntityFrameworkCoreSqlServerSettings>? configureSettings = null,
     Action<IServiceProvider,DbContextOptionsBuilder>? configureDbContextOptions = null) where TContext : DbContext
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

No branches or pull requests

1 participant