Note: this article is published on 07/01/2024.
This series of articles will discuss Software Design Principles.
- Design Principle (0): Design Principle vs Design Pattern
- Design Principle (1): SOLID in Concept
- Design Principle (2): Inversion of Control (IoC) Principle --- this article
A - Introduction
Inversion of Control is a principle in software engineering which transfers the control of objects or portions of a program to a container or framework. We most often use it in the context of object-oriented programming.
In contrast with traditional programming, in which our custom code makes calls to a library, IoC enables a framework to take control of the flow of a program and make calls to our custom code. To enable this, frameworks use abstractions with additional behavior built in.
The content of this article:
- A - Introduction
- B - Inversion of Control
- What is Dependency?
- Dependency Management
- Inversion of Control (IoC)
- IoC Container or DI Container
- What is a DI Container?
- IoC Implementation
- C - Inversion of Control Principle
- IoC, DIP, DI and IoC
- Step 1: Inversion of Control
- Step 2: Dependency Inversion Principle
- Step 3: Dependency Injection
- Step 4: IoC Container
- Lifecycle of the DI Containers
- Open Source Containers for .NET
- D - IoC implementation
- E - Dependency Injection implementation
- DI Factors
- DI using Constructor, Method or Property
B - Inversion of Control



C - Inversion of Control Principle



- Step 1: Inversion of Control

- Step 2: Dependency Inversion Principle

- Step 3: Dependency Injection

- Step 4: IoC Containers

- Lifecycle of the DI Containers
- Register: The container must know which dependency to instantiate when it encounters a particular type. This process is called registration. Basically, it must include some way to register type-mapping.
- Resolve: When using the IoC container, we don't need to create objects manually. The container does it for us. This is called resolution. The container must include some methods to resolve the specified type; the container creates an object of the specified type, injects the required dependencies if any and returns the object.
- Dispose: The container must manage the lifetime of the dependent objects. Most IoC containers include different lifetimemanagers to manage an object's lifecycle and dispose it.
- Containers for .NET
- Unity
- StructureMap
- Castle Windsor
- Ninject
- Autofac
- DryIoc
- Simple Injector
- Light Inject
- .NET Core default DI Container
D - IoC implementation
As discussed above IoC is a generic term for a program workflow to be inverted. The implementation is usually the Dependency Injection, but not limited to DI. In general, there are more than several ways to implement the IoC, such as
- Understanding Inversion of Control in C# (scholarhat.com)
- ervice Locator
- Event
- Delegate
- Dependency Injection

- IoC and Dependency Injection
- Dependency Injection
- Constructor Injection
- Setter Injection (Property Injection)
- Method Injection
- Dependency Lookup (DL)
- Service Locator Pattern
- Factory Pattern
- JNDI Lookup Pattern
- Dependency Injection

E - Dependency Injection implementation
Specifically for Dependency Injection Implementation
- Dependency injection Factors - Wikipedia
- Service
- Client
- Interface
- Injector --- assembler, container, provider or factory
- Understanding Dependency Injection Using Constructor, Property, And Method In C# (c-sharpcorner.com)
- Constructor
- Property
- Method
- Dependency injection in c# with an example | by Kamlesh Singh | Medium --- Console without Container
- Constructor
- Property
- Method
- Implementation of Dependency Injection In C# (scholarhat.com)
- Constructor
- Property
- Method
- DI Container
References:
- Inversion of control - Wikipedia
- Understanding Inversion of Control in C# (scholarhat.com)
- Learn Inversion of Control Principle (tutorialsteacher.com)
- IoC and Dependency Injection: Key Differences in Spring (howtodoinjava.com)
- What is IoC Container or DI Container (scholarhat.com)
- Dependency injection - Wikipedia
- Understanding Dependency Injection Using Constructor, Property, And Method In C# (c-sharpcorner.com)
- Dependency injection in c# with an example | by Kamlesh Singh | Medium --- Console without Container
- Implementation of Dependency Injection In C# (scholarhat.com)

Join the conversation! Your thoughts help the community grow.