Skip to content

Instantly share code, notes, and snippets.

@PlexXoniC
Created August 22, 2012 14:37
Show Gist options
  • Save PlexXoniC/3426207 to your computer and use it in GitHub Desktop.
Save PlexXoniC/3426207 to your computer and use it in GitHub Desktop.
Signlar.Autofac
this is called from App_Start:
public class MvcInitializer : IStateChange
{
private readonly ILifetimeScope _container;
public MvcInitializer(ILifetimeScope container)
{
_container = container;
}
#region IStateChange Members
public void Apply()
{
//moved to app_Start/mvc_init
//SignalR.Autofac
//GlobalHost.DependencyResolver = new SignalR.Autofac.AutofacDependencyResolver(_container);
//RouteTable.Routes.MapHubs();
//add the container to the lifetime object in the new MVC init
App_Start.MVCInit.lifetimeScope = _container;
RouteTable.Routes.MapHubs();
//DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(_container));
//AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
#endregion
//the init section
[assembly: WebActivator.PostApplicationStartMethod(typeof(Mmits.WebApp.App_Start.MVCInit), "Init")]
namespace Mmits.WebApp.App_Start
{
public class MVCInit
{
public static ILifetimeScope lifetimeScope; //gets set in the MVCInitilizer.Apply() called from App_Start
public static void Init()
{
//SignalR.Autofac
GlobalHost.DependencyResolver = new SignalR.Autofac.AutofacDependencyResolver(lifetimeScope);
RouteTable.Routes.MapHubs();
//autofac
DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(lifetimeScope));
AreaRegistration.RegisterAllAreas();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment