Composite ASP.NET MVC Applications WCSF, SCSF, and Prism Style

I put together a wholesale e-commerce site for a client using the ASP.NET MVC Framework instead of the usual ASP.NET Webforms. If using ASP.NET webforms, I probably would have used the Web Client Software Factory because the website itself is a classic composite web application. Daring to be bold, however, this website was also a perfect candidate for the ASP.NET MVC Framework and I really like the simplicity of MVC and the ability to create your own ControllerFactory and then use your favorite IoC Tool to inject dependencies into those controllers.

 

ModuleInitializers

Like the WCSF, I use the concepts of Business Modules and ModuleInitializers:

 

public interface IModuleInitializer
{
    void Init();
    void Load(IContainer container, RouteCollection routes);
}

 

Each module has the ability to register its controllers and services into the module container as well as add routes. You might do the following:

 

public EcommerceModule : IModuleInitializer
{
    public void Init() {}
    
    public void Load(IContainer container, RouteCollection routes)
    {
        container.Register<IProductCatalog,ProductCatalog>();
        container.RegisterController<ProductsController>("Products");
        
        // Add Any Routes...
    }
}

 

If you are interested in understanding ModuleInitializers from a WCSF point-of-view, you can check out the following screencast:

 

 

Hierarchy of IoC Containers

Just like in the WCSF, there is a root IoC Container that essentially contains global services and then each business module has its own IoC Container, which is a child container of the root container. Therefore as shown above, the EcommerceModule has its own IoC Container that gets passed in for controller and service registration. It is that IoC Container that is used in the Custom Controller Factory to inject dependencies into the ProductsController. Of course any dependencies that are not fulfilled by the module IoC Container will try to be fulfilled by the root IoC Container.

As it so happens I am using Unity from Microsoft Patterns & Practices in the background, but I could easily replace it with Windsor or Spring at the drop of a hat ( it is pluggable ). You can read more about Unity Hierarchy here:

 

Unity IoC

 

If you are interested in using Unity in the ASP.NET MVC Framework, you can check out these screencasts:

I will note that the way I show creating controllers and injecting their dependencies in the screencast is not the same way I do it with my Composite ASP.NET MVC “Framework”. When you are getting into registering controllers in separate modules and a hierarchy of IoC Containers you have to do things a bit differently :) That being said, most ASP.NET MVC Framework Applications can use Unity as mentioned in the screencasts.

 

Check out SCSF, Prism and Caliburn Examples - Similar Techniques

I haven't looked at the Fourth Drop of Prism yet, but previous examples showed off good use of Unity for composite WPF Applications. I also found out about Caliburn - An MVP Framework for WPF Composite Applications that apparently shows off composite WPF Guidance. And, of course, you can always look at the newly released SCSF for Visual Studio 2008.

A lot of really nice inspiration for developing your composite applications, whether they be smart clients, ASP.NET Webform, ASP.NET MVC, or WPF.

posted on Wednesday, April 30, 2008 10:38 PM

My Links

Post Categories

Article Categories

Archives

Loose-Leaf Tea