Advanced Search
Search Results
5 total results found
Duplicating .NET Core DI
NOTE: If you are looking for how to access DI services, see this: HowTo Access DI Services Here are the steps to duplicating the .NET Dependency Injection process, to create a ServiceProvider instance. This is especially useful in unit testing, for classes an...
Unit Testing with IServiceProvider
When you create unit tests for class types that directly use DI to retrieve dependencies, you will need a way to give them a reference to a service provider (IServiceProvider). This is transparently done by the runtime.But, we have to mimic it for unit testin...
IServiceProvider vs IServiceScopeFactory
References: Net Core DI Truths Internet’s Claim of Anti-Patterns Contrary to what the internet says about service locator usage as anti-pattern, there will always be the need for logic to dynamically access services from DI.This is because the NET Core runti...
Net Core DI Truths
References: NET Core DI Best Practices Here’s a list of behaviors of the NET Core DI registry: All dynamic access to services (from DI) are requested through a service provider.This is what people call a service locator. For example:var foosvc = _servic...
HowTo Access DI Services
NOTE: If you are looking for how to generate an instance of ServiceProvider, outside of NET Core runtime, like for a unit test, see this: Duplicating .NET Core DI Here’s a good reference on how DI scoping works: The dangers and gotchas of using scoped service...