Last active
October 24, 2019 14:44
-
-
Save alistairjevans/393d551dc7a107fe3de2263c11d45a71 to your computer and use it in GitHub Desktop.
Scope throws an exception
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
// Get a host builder | |
var hostBuilder = CreateHostBuilder(args); | |
// Add our service as scoped. | |
hostBuilder.ConfigureServices(srv => | |
{ | |
srv.AddScoped<MyAsyncOnlyDisposableObject>(); | |
}); | |
// Get our container | |
var host = hostBuilder.Build(); | |
using(var serviceScope = host.Services.CreateScope()) | |
{ | |
var myObject = serviceScope.ServiceProvider.GetRequiredService<MyAsyncOnlyDisposableObject>(); | |
} // Exception thrown here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment