Service locator pattern is one of the most commonly used patterns. In general, this pattern is used along with other patterns like Adapter Pattern, Observer Pattern, Dependency Injection Principles and many more. In this post, however, we will be talking about its use with dependency injection, which is one its many uses.
While I was exploring Autofac, I found AsImplementedInterfaces quite interesting. Not only because it is useful, but also because if we are not careful with its use, we may end up with unexpected application behavior.
A DI container takes the responsibility of instantiating and providing the dependency instances, irrespective of the level of dependencies. As a result, it is a container that manages the scope of the instantiated objects.
Dependency Injection (DI) is a technique that helps us achieve loose coupling between objects and their collaborators. In this post, we will use constructor based dependency injection, however, we are not going to use any DI container for now.
If a component or class depends upon other components to complete its operations, then these other components are dependencies for this class. Our class can have these dependencies as implicit or explicit dependencies.
A loosely coupled application has good isolation among its classes, modules and assemblies. Therefore, if we make a change to one part of the application, we only need to update the relevant modules. We do not need to make changes throughout the application.
It is a best practice to use interfaces instead of concrete classes. These interfaces can then be mocked at the time of unit testing, which will prevent any call to the actual database. Also, it is a good practice to stop "newing-up" objects in classes.

Pre/Post build events are useful when we wish to perform some operation before/after a project is built. These operations are nothing but the Shell commands being used from the command line. A build event can be formed using a single, multiple, or conditional commands.
Learn how the Null Object pattern replaces null references with do-nothing objects to avoid repeated null checks and NullReferenceException errors in C#.
Object relationships define how different classes interact in an application. Collaboration (uses-a), Aggregation (has-a), and Inheritance (is-a) are key types. For instance, Customer and Order use aggregation, while Order and OrderItem show composition.
It has been quite a long time since "var" was introduced, yet it is still a topic of debate among .net developers.
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegisterMembers onlyWrite an article and earn +1,000 SHARP when it is approved.
Write an article