Skip to content

Instantly share code, notes, and snippets.

@alistairjevans

alistairjevans/program.cs

Last active Oct 24, 2019
Embed
What would you like to do?
Scope throws an exception
// 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
You can’t perform that action at this time.