Upgrading MVC 3 to MVC 5

Feb 7, 2014 at 7:02 PM

We're just upgrading to VS 2013, meaning our MVC 3 projects, while they build, don't have the Intellisense. So, it's time to upgrade the projects to MVC 5.

One of our projects uses SimpleInjector, and I'm completely lost as to how to get the latest version working. The old project created a SimpleInjectorMVC3.cs file - do I still need that? Is there an MVC 5 equivalent? Also, it looks like the docs now put a lot of code in the Global.asax file - what interfaces am I putting to the container.Register statement?

I'm completely at sea on this, and would really appreciate the help. Upgrading is going to be hard enough (and of course, we have to justify the ROI on this) and any more difficulties with third-party libraries just make our job more difficult.

Also, for integrating SimpleInjector into an existing (upgraded to MVC 5) project, any advice?


Jim Stanley
Blackboard Connect
Feb 7, 2014 at 9:12 PM
Hi Jim,

Hmmm... I don't think that SimpleInjectorMVC3.cs is something that was ever included in one of the Simple Injector integration packages. Are you sure this is not something custom or from another source?

I think the easiest thing you can do is create an empty (temporary) MVC5 web application and include the Simple Injector MVC Integration Quick Start NuGet package. (The NuGet package id is SimpleInjector.MVC3, but it works for MVC4 and MVC5 as well.) This shows you right away what you need in your real project. What the quick start package adds an SimpleInjectorInitializer.cs file with an SimpleInjectorInitializer class containing an Initialize method that gets run during 'post application start'. The initialize method does two important things: registers all your MVC controllers and registers the SimpleInjectorDependencyResolver. Further more it registers an Simple Injector specific AttributeFilterProvider and it calls Verify.

The SimpleInjectorInitializer class is just meant to get new users started quickly. You can also move all initialization logic into the Global.asax if this works better for you.

If you have any other questions, please let me know.
Marked as answer by dot_NET_Junkie on 2/26/2014 at 1:13 PM
Apr 4, 2014 at 7:51 AM
Edited Apr 4, 2014 at 7:52 AM
Hi there, I have a similar case, I had to make a downgrade from .Net 4.5/MVC5.1, to 4.0/MVC5.0, SimpleInjetor is not being hired anymore, there was a change in the security(authentication), this is the Global.asax file content now:
public class MvcApplication : System.Web.HttpApplication
        protected void Application_Start()
            WebSecurity.InitializeDatabaseConnection("DefaultConnection", "tUser", "UserID", "UserName", autoCreateTables: false);
Since I'm using Onion Architecture, I have a class library project in charge of injecting the DI, I did this before (you helped me btw), and now this is a new challenge.

I'm using this:
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(SimpleInjectorWebCommon), "Start")]
Thanks in advance for your help.
-- JR
Apr 4, 2014 at 8:03 AM
Hi Jerori,

I'm sorry, but I'm not sure I understand what the problem is. Can you elaborate a bit?
Apr 4, 2014 at 6:31 PM
Sure, SimpleInjector is not working because SimpleInjectorWebCommon (class library- where [assembly : WebActivatorEx..] is ) is not being call by IIS anymore.
Apr 4, 2014 at 7:53 PM
That's new to me. In that case just move the code that's in the Initialize method to the App_Start method in Global.asax.
Apr 5, 2014 at 6:59 PM
Sorry, It was my bad, I forgot to add the dll as reference. Thanks.