This project is read-only. Controller Factory


The Controller Factory implementation, MVCContrib.ControllerFactories.SpringControllerFactory, for MVC Contrib allows the configuration of IController implementations within the DI container.

Custom Controller Factories need to be configured in order to be recognized by the MVC framework. This configuration will need to take place within the Application_Start() method of the Globabl.asax.cs code file in your MVC Application. In order for the Controller Factory to share the context with other components in the application, developers should create the context before setting the MVC framework default controller factory. Passing the context to the static Configure() method will allow this sharing to occur. Either IApplicationContext or IObjectFactory instances are supported.

The names for each IController instance in the configuration should match the Type.Name of each concrete controller implementation that is created.

Note: The version included with MVCContrib was developed and tested against version 1.1 of However, no functionality specific to 1.1 was used and there is no reason why the class could not be compiled against a prior version of, if that is requirement for usage.

Example Usage

The following is an example of the additions that need to be made in Global.asax.cs:

protected void Application_Start(object sender, EventArgs e)
    //This example just sets the default context for use with the Controller
    //Factory.  An IObjectFactory instance is also supported, if greater control over
    // is desired.

    IApplicationContext ctx = ContextRegistry.GetContext();


    //more configuration code for the MVC framework

Below is a sample IController implementation that will be configured in

public class SimpleController : IController
    public void Execute(ControllerContext controllerContext)
        //controller code goes here

The configuration of this controller in looks like this:

<objects xmlns=""

  <object id="SimpleController" singleton="true" type="Examples.SimpleController"/>


Last edited Dec 14, 2007 at 7:12 PM by darrenstokes, version 3


rafal_g Nov 25, 2008 at 9:25 AM 
This example is broken - controller cannot be configured as singleton! It must be a prototype (use singleton=false).
Otherwise application will not work correctly.