.Net, Programming

High Performance Munq IOC Container For Asp.Net MVC And Web Form

IOC is a pattern which decouples the use of an interface from the concrete implementation of that interface. By eliminating this coupling:

  •  The code can be tested by using special test implementations of the interface.
  •  Fewer DLLs need to be deployed on each tier of a multi-tiered deployment.
  •  Project compilation may be sped up as there are fewer project dependencies.
  •  Alternate implementations of the interface can be configured for use without requiring changes to the main application code. This could mean changing from MSSQL to Oracle with a simple configuration file change.

An IOC Container is a pattern which allows the application to create an instance of the interface without knowing the specific concrete class that will be used.

Munq is a very small, fast dependency injection container designed for ASP.NET applications, both Webforms and MVC. It has, by design, limited features. The main goal has been to minimize the CPU required for Resolving types from the container.

Goal:

  1. Speed. High volume websites need to minimize the amount of work each page request needs to execute. Even 1/10th of a second can make a difference of a user’s perception of the site.
  2. Simplicity. Munq does one thing but does it well. It resolves requests for instances of Types by executing Factories that have been previously registered in the container.
  3. Provide Web Lifetime Management. Windows applications can get by with a container that has the option of creating a new instance each request or re-use the same instance. In the web application world, objects can have lifetimes that only span the current Request, the user’s Session, or be Cached reduce database load and access delays.

Here below is the output by testing in the web application which implemented the IWebService interface and all Containers were configured to return new instances for all interfaces which were a shared instance. Running 10000 iterations for each use case had the following results.

Container Ticks/Iteration
None 5.1746
Munq 68.3385
Funq 76.2779
Unity 613.0442
Autofac 877.035
StructureMap 280.9433
Ninject 4122.1138
Ninject2 5059.9001
Windsor 4206.1035

Munq DI IOC Container is the smallest, fastest IOC container that I know of. It is faster than any of the big players, Unity, Windsor Castle, Ninject, StructureMap, etc.

You can download it from package manager:

PM> Install-Package Munq.IocContainer

Also, you can download it from the visual studio:

Munq Nuget

For more details:
About Munq and download
Using Munq IOC Container Version 3 in ASP.NET MVC 3

Tagged

Leave a Reply

Your email address will not be published. Required fields are marked *