microsoft / microsoft/aspire

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

Open
#7,020 2 comments 2 reactions 0 assignees View on GitHub
area-integrations sqlserver
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] 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

```cs
builder.AddSqlServerDbContext("sqldb-model", configureDbContextOptions: (options) =>
{
options.UseLazyLoadingProxies()
.ReplaceService()
.AddInterceptors(
provider.GetRequiredService(),
provider.GetRequiredService>()
);
});
```
The original problem is that I can't add a generic `AddInterceptor()` 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

```cs
public static void AddSqlServerDbContext<[DynamicallyAccessedMembers(RequiredByEF)] TContext>(
this IHostApplicationBuilder builder,
string connectionName,
Action? configureSettings = null,
Action? configureDbContextOptions = null) where TContext : DbContext
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the AddSqlServerDbContext API and its configureDbContextOptions handling. Trace how the service provider is created and scoped, then determine the changes needed for the proposed callback signature. Done means the callback can resolve scoped services for DbContext configuration and the existing overload behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.