Which PreApplicationStartMethod method to use?

I noticed that when I installed StructureMap from NuGet into my ASP.NET MVC3 project, the Dave Ebbo WebActivator package was also added as a dependency.

WebActivator provides the PreApplicationStartMethod attribute, and in the code template added during installation, it is used to initialize the IoC container and the dependent converter in its own class instead of doing this inside the Global.asax Application_Start method.

Given that ASP.NET 4 already has its own System.Web.PreApplicationStartMethodAttribute , why did WebActivator have to provide its own version, and for StructureMap, use this?

I assume that I do not need to use the WebActivator option?

Added code for Darin:

 using System.Web; using System.Web.Mvc; using StructureMap; [assembly: WebActivator.PreApplicationStartMethod( typeof(MyMvcApp.App_Start.StructuremapMvc), "Start")] // or [assembly: PreApplicationStartMethod( typeof(MyMvcApp.App_Start.StructuremapMvc), "Start")] namespace MyMvcApp.App_Start { public static class StructuremapMvc { public static void Start() { var container = (IContainer) IoC.Initialize(); DependencyResolver.SetResolver(new SmDependencyResolver(container)); } } } 
+7
source share
1 answer

NuGet packages for DI containers in ASP.NET MVC 3 usually prefer to use WebActivator to avoid interacting with any existing code that you might have in Application_Start . Ninject uses exactly the same approach.

You can have several WebActivator.PreApplicationStartMethod attributes in the application and up to .NET 4.5 one System.Web.PreApplicationStartMethodAttribute .

+5
source

All Articles