Inject IDbContextFactory or DbContext directly?
Hey,
I was working with a project earlier that I've made and I saw I was injecting the db context with
I was doing this:
I read somewhere that you should just inject the DB Context directly, and let the DI handle the lifetime of it, but I was unsure if this was bs or not?
Does anyone have any tips surrounding this?
Thanks
I was working with a project earlier that I've made and I saw I was injecting the db context with
IDbContextFactory<ApplicationDbContext> and then manually creating a db context every time I was going to use it.I was doing this:
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();I read somewhere that you should just inject the DB Context directly, and let the DI handle the lifetime of it, but I was unsure if this was bs or not?
Does anyone have any tips surrounding this?
Thanks
