When you resolve the registered type, the container return an object of that type. By default, the container does not hold the object reference. You can change the lifetime of the instance in different ways.
Registering type maps (from and to) is the first step in DI patterns. Unity provides a couple of ways to register types.
“Unity” is another framework for DI and some more. It is part of MS Enterprise Library but can be installed separately through NuGet. The main purposes of “Unity” are late binding and loose coupling.
The “Command” is a design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time.
A factory is an object for creating other objects. A factory object typically has a method to create any specific object and return the reference to it. These methods optionally accept parameters defining how the object is created.
Singleton restricts the instantiation of a class to one object. It is the one of the basic design patterns and easy to implement.
You know that it is not a good practice to use destructors to clean up your objects. You are not supposed to disrupt the garbage collection process either. The “System.Object” class has the “Finalize()” method. But in C#, you cannot override this method. You need to use the destructor instead.
So how do we cleanup used objects or resources?
Ninject is one of the most popular DI (Dependency Injection) frameworks. It is robust and easy to use; moreover it is free. You can always use DI pattern for your application but Ninject helps you integrate DI into your application.