mvc5中使用autofac注册SignalR
1.引用autofac.SignalR
2.Startup
public void Configuration(IAppBuilder app) { DependencyConfig.RegisterDependencies(app); }
3.RegisterDependencies
//Register your SignalR hubs. builder.RegisterHubs(Assembly.GetExecutingAssembly()); var container = builder.Build(); DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(container)); var configuration = new HubConfiguration { Resolver = new Autofac.Integration.SignalR.AutofacDependencyResolver(container) }; app.MapSignalR(configuration);
4.Hub中直接注入
private ILog _log; private IHelper _helper; private IGJYB _gJYB; private IReconciliation _reconciliation; public PushHub(IHelper helper, ILog log, IGJYB gJYB, IReconciliation reconciliation) { _log = log; _helper = helper; _gJYB = gJYB; _reconciliation = reconciliation; }