This project is read-only.

MvcExtensions with Unity

May 28, 2012 at 5:43 PM

Good day, hazzik! Could you post a example of using Unity with MvcExtensions, please. Or do you still recommend Windsor? Do you plan to stop producing or make new commercial product on this basis?

May 28, 2012 at 8:46 PM

Hi, using Unity almost the same as Windsor.

1. Download package from nuget (or you could download release as zip archive):

install-package MvcExtensions.Unity 

2. Inherit your application from MvcExtensions.Unity.UnityMvcApplication

3. Register your services in modules (IModule)

Aslo examples for each popular IoC container are located in 'Samples' directory in the source control.

 >Do you plan to stop producing or make new commercial product on this basis?

No and no. Now we are developing version 2.5 which is focused on easily extension of fluent metadata and validation enchancements. Also in plans support for native MVC IoC adapters (such as Ninject.Mvc3, Autofac.Web.Mvc, Unity.Mvc3, etc) and possible support of WebActivator.

May 28, 2012 at 8:48 PM
Edited May 28, 2012 at 8:48 PM

Also we had moved source code for version 2.5 to github

May 29, 2012 at 9:32 AM

Thanks! But... I have a error in my mvc4 application.

System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
       at MvcExtensions.Bootstrapper.Execute[TTask](IEnumerable`1 tasks) in d:\BuildAgent-02\work\5dc85169f18b1630\src\MvcExtensions\Bootstrapper\Bootstrapper.cs:line 176
       at MvcExtensions.Bootstrapper.ExecuteBootstrapperTasks() in d:\BuildAgent-02\work\5dc85169f18b1630\src\MvcExtensions\Bootstrapper\Bootstrapper.cs:line 104
       at MvcExtensions.ExtendedMvcApplication.Application_Start() in d:\BuildAgent-02\work\5dc85169f18b1630\src\MvcExtensions\ExtendedMvcApplication.cs:line 75
  Call stack location: MvcExtensions.dll!MvcExtensions.ExtendedMvcApplication.Application_Start() Line 76

The file 'd:\BuildAgent-02\work\5dc85169f18b1630\src\MvcExtensions\ExtendedMvcApplication.cs' does not exist.
Looking in script documents for 'd:\BuildAgent-02\work\5dc85169f18b1630\src\MvcExtensions\ExtendedMvcApplication.cs'...
Looking in the projects for 'd:\BuildAgent-02\work\5dc85169f18b1630\src\MvcExtensions\ExtendedMvcApplication.cs'.
The file was not found in a project.

My code:

public class MvcApplication : UnityMvcApplication
        public MvcApplication()
        public class RegisterRoutes : RegisterRoutesBase
            public RegisterRoutes(RouteCollection routes)
                : base(routes)
            protected override void Register()
                    "{controller}/{action}/{id}", // URL with parameters
                    new { controller = "Home", action = "Index", id = UrlParameter.Optional }

public class RegisterServices : IModule
        public void Load(IUnityContainer container)
            container.RegisterType<IMyService, IMyService>(new PerRequestLifetimeManager());

Packages installed: Microsoft.Practices.ServiceLocation, Microsoft.Practices.Unity, MvcExtensions, MvcExtensions.Unity.

May 29, 2012 at 10:19 AM

SpaceMarine, which versions exactly are you using? 

May 29, 2012 at 11:09 AM

VS 11.0.50214.1 betarel; AspNetMvc 4.0.10906.0; CommonServiceLocator 1.0; Unity 2.1.505.0; MvcExtensions 2.5.0-rc8005 pre; MvcExtensions.Unity 2.5.0-rc8005 pre

all installed without errors from package console.