service locator
An anti-pattern in which code asks a global container for its dependencies at the point of use instead of receiving them in its constructor.
In more detail
It hides what a class needs and makes it hard to test. The .NET container is meant for composition at the edges, not to be called from everywhere.
Related terms
- dependency injection — Giving an object the collaborators it needs from outside, usually through its constructor, instead of letting it create or look them up itself.
- service provider — The built dependency injection container, which creates and hands out services according to their registrations.
Taught in
- The Dependency Injection Container: Scopes and Lifetimes — Modern .NET Core, C# & Enterprise Microservices