I'm sure we already have seen the following type of code in our titan project

 

and 

 

The key purpose of these code is to allow ASP.NET MVC framework to use the controller instance from IoC containter. Why have we done it? There are many reasons but i'm listing here two of them

1. We creates our custom controller constructor that is not build in MVC framework.  Please see the following code snippet. Basically ASP.NET MVC framework always create the controller instance with it's own constructor.  So, if the controller is not instantiated with your construction, then your services (userService, organizationService) will not be instantiated.

 

 

2. We could seperate the controller froms web application to other class library. 

However, you already understood that how the ASP.NET MVC framework implmented factory method pattern to allow to extend the controller factory class.

 

 

 

 

 

 

 

Add new comment