I noticed that when I installed StructureMap from NuGet into my ASP.NET MVC3 project, Dave Ebbo's WebActivator package was also added as a dependency.
WebActivator provides a PreApplicationStartMethod
attribute and, in the boilerplate code added at install time, it is used to initialise the IoC container and dependency resolver in it's own class, instead of doing this inside Global.asax
's Application_Start
method.
Given that ASP.NET 4 already has its own System.Web.PreApplicationStartMethodAttribute
why was it necessary for WebActivator to supply its own version and for StructureMap to use that?
I am guessing I don't have to use WebActivator's variant?
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));
}
}
}
WebActivator.PreApplicationStartMethodAttribute
over the ASP.NET 4 providedSystem.Web.PreApplicationStartMethodAttribute
. – Swanner