Factory package aanmaken #2
Replies: 4 comments
-
|
Welke generic factory bedoel je hier mee? |
Beta Was this translation helpful? Give feedback.
-
|
Voor het aanmaken van bijv, de context |
Beta Was this translation helpful? Give feedback.
-
|
I think this was about the efcore dependency injection using service scope factory before dotnet 5. ServiceScopeFactory registration:public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddDbContext<ApplicationDbContext>(
options => options.UseSqlServer("name=ConnectionStrings:DefaultConnection"));
}ServiceScopeFactory injection:private readonly IServiceScopeFactory scopeFactory;
public MyController(IServiceScopeFactory scopeFactory)
{
this.scopeFactory = scopeFactory;
}ServiceScopeFactory usage:public void DoSomething()
{
using(var scope = serviceScopeFactory.CreateScope())
{
var context = scope.ServiceProvider.GetService<MyDataContext>();
// ...
}
}DbContextFactory registration:public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddDbContextFactory<ApplicationDbContext>(
options =>
options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Test"));
}DbContextFactory injection:private readonly IDbContextFactory<ApplicationDbContext> _contextFactory;
public MyController(IDbContextFactory<ApplicationDbContext> contextFactory)
{
_contextFactory = contextFactory;
}DbContextFactory usage:public void DoSomething()
{
using (var context = _contextFactory.CreateDbContext())
{
// ...
}
} |
Beta Was this translation helpful? Give feedback.
-
|
It might also connect nicely to our GenericFactory |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Wij moeten de generic factory packagebaar maken
Beta Was this translation helpful? Give feedback.
All reactions