IOC documentation out of date re: scoped vs singleton resolution?

Hi, quick qn: I came across this guy’s Medium post + your commit to implement his idea, and if I interpret the outcome correctly, the documentation here:

https://docs.servicestack.net/netcore#scoped-dependencies

is now out of date? (as actually, those dependencies would resolve in scope correctly, rather than as singletons?) Or am i misunderstanding the feature?

https://medium.com/@giangnn/registering-dependencies-in-servicestack-net-core-with-request-scope-e32ba8061672

The NetCoreContainerAdapter.cs still uses the IHttpContextAccessor if it’s registered, but ASP .NET Core no longer registers it by default so you’d need to register it manually.

Otherwise when you add a scoped dependency in ASP .NET Core’s IOC you can resolve it with IRequest.TryResolveScoped<T>() which will resolve it from ASP.NET Core’s RequestServices Scope otherwise using IRequest.TryResolve<T>() will first resolve it from RequestServices if it exists otherwise falls back to normal singleton or transitive IOC dependency.

1 Like