You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have support for EF Core (#61) ready, it would be a great addition to support the built in dependency injection framework in ASP.NET: Currently if you only register the implementation like this: builder.Services.AddScoped<IDbContextScopeFactory, DbContextScopeFactory>(); builder.Services.AddScoped<IAmbientDbContextLocator, AmbientDbContextLocator>();
the context must have a parameterless constructor. As DBContextCollection includes the following line: Activator.CreateInstance<TDbContext>().
To support a context with parameters provided by DI (like auto generated from scaffolding), the library could have a default factory like this:
`internal class DBContextLocator : IDbContextFactory
{
private readonly IServiceProvider _serviceProvider;
public DBContextLocator(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public TDbContext CreateDbContext<TDbContext>() where TDbContext : class, IDbContext
{
return ActivatorUtilities.CreateInstance(_serviceProvider, typeof(TDbContext)) as TDbContext ??
throw new NotImplementedException(typeof(TDbContext).Name);
}
}`
Perhabs there are better ways to create the context, but I think you get the idea.
The text was updated successfully, but these errors were encountered:
If you have support for EF Core (#61) ready, it would be a great addition to support the built in dependency injection framework in ASP.NET: Currently if you only register the implementation like this:
builder.Services.AddScoped<IDbContextScopeFactory, DbContextScopeFactory>(); builder.Services.AddScoped<IAmbientDbContextLocator, AmbientDbContextLocator>();
the context must have a parameterless constructor. As DBContextCollection includes the following line:
Activator.CreateInstance<TDbContext>()
.To support a context with parameters provided by DI (like auto generated from scaffolding), the library could have a default factory like this:
`internal class DBContextLocator : IDbContextFactory
{
private readonly IServiceProvider _serviceProvider;
Perhabs there are better ways to create the context, but I think you get the idea.
The text was updated successfully, but these errors were encountered: