Created
November 28, 2017 11:48
-
-
Save MrAntix/8668a7cf6821437589502b30681e4c70 to your computer and use it in GitHub Desktop.
EF: Allows usual transactions for scope injected instances and a factory method to create contexts which are disposed of by the caller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddDbContext<MyDataContext>( | |
o => o.UseSqlServer(settings.ConnectionString), | |
ServiceLifetime.Scoped, | |
ServiceLifetime.Singleton); | |
services.TryAddSingleton<Func<MyDataContext>>(sp => | |
() => new MyDataContext(sp.GetService<DbContextOptions<MyDataContext>>()) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment