HostContext.ResolveService + IDisposable

You can’t have per-request scoped dependencies when executing a Service outside the context of a HTTP Request (which is where request scoped dependencies are tied to).

I’d recommend against using Request Scoped dependencies, in addition to restricting usage of dependencies within the context of a HTTP Request, it relies on environment-specific constructs to support request scope whose nuanced behavior can differ in alt environments (e.g. ASP .NET Web FX vs Unit Tests), it’s less efficient for pooled resources. There shouldn’t be any reason to use Request Scope, if you need per-request storage you can store objects in the IRequest.Items dictionary which is available throughout the entire Request Pipeline.

Basically if your dependencies only use Thread Safe dependencies register it as a singleton (the default):

container.AddSingleton<IMyDep>(c => new MyDep { Name = "bar" });
container.Register(c => new MyDep(c.Resolve<IDep>()));
container.RegisterAutoWiredType(typeof(MyDep));
container.RegisterAutoWiredType<MyDep>();

Otherwise register it as a Transient dependency, e.g:

container.AddTransient<IMyDep>(c => new MyDep { Name = "bar" });
container.Register(c => new MyDep()).ReusedWithin(ReuseScope.None); 
container.RegisterAutoWiredType(typeof(MyDep)).ReusedWithin(ReuseScope.None); 
container.RegisterAutoWiredType<MyDep>().ReusedWithin(ReuseScope.None); 

In ASP .NET Core any disposables created are tracked in an AsyncLocal Dictionary are disposed after calling the Service in both HTTP Request and out-of-band Services where it automatically calls RequestContext.Instance.ReleaseDisposables() when called with a using, e.g:

using var service = HostContext.ResolveService<MyService>(base.Request);
//...