Skip to content

Instantly share code, notes, and snippets.



Last active Oct 24, 2019
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 =>
// 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