scan for and register DbContext?
Closed this issue · 3 comments
jasonswearingen commented
Is there a way to automatically scan for and register a dbcontext using Scrutor? I am not having luck figuring that out.
I have to do it the normal old way:
builder.Services.AddDbContext<PoliceAppSqlDbContext>(
contextLifetime: ServiceLifetime.Singleton
, optionsAction: options =>
{
options.UseNpgsql(builder.Configuration.GetConnectionString("SqlDbConnection"));
});
Thank you
khellang commented
Hey @jasonswearingen! 👋🏻
You could do something like .AssignableTo<DbContext>().As<DbContext>()
, but you'd still need to configure the options separately, so I would recommend just doing it the "normal" way 😄
jasonswearingen commented
thank you, that's what I figured, as the AddDbContext
extension seems to do a lot of stuff internally.
But for literally everything else, Scrutor makes things so much more pleasant (I'm a hesatant DI noob.. but Scrutor makes it great)
jasonswearingen commented
if someone else has this issue, you can override the DbContext.OnConfiguring() method and configure there.