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
{{ message }}
Repository navigation
AddDbContext with ServiceLifetime.Scoped should pass scoped IServiceProvider to optionsAction #8797
When registering DbContext via AddDbContext(Action<IServiceProvider, DbContextOptionsBuilder>) with ServiceLifetime.Scoped i expect IServiceProvider argument passed to the optionsAction to be IServiceProvider from IServiceScope.
Unfortunately AddDbContext adds DbContextOptions as singleton. Should'nt DbContextOptions be also added scoped when using ServiceLifetime.Scoped ?
In my case i resolve many DbContext's which need to use same DbConnection provided by a scoped IDbConnectionProvider. This enables me to call SaveChanges on different contexts in same transaction.
Activity
ajcvickers commentedon Jun 9, 2017
@prochnowc DbContextOptions is intentionally registered as singleton. See #6863 for details.
Note for triage: capturing the scoped service provider is a good idea. I wasn't sure how to do it before, but I think I have an idea now.
prochnowc commentedon Jun 12, 2017
Thanks for the reply. I've already worked it around registering DbContextOptions on my own as scoped service.
Allow scoped application services to be accessed from the context
Allow scoped application services to be accessed from the context