如何让 Autofac 将依赖项注入信号器集线器,我已经尝试了所有唯一的问题,其中许多现在已经过时,我已经尝试从他们的站点下载 signalr.autofac,但似乎没有任何效果?
我的 Autofac
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
//Register Context
builder.Register(c => new myContext()).As<IUnitOfWork>().InstancePerLifetimeScope();
//Repositories
builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IBaseRepository<>)).InstancePerHttpRequest();
//Service Layer
builder.RegisterType<UserService>().As<IUserService>().InstancePerHttpRequest();
//other services etc
builder.RegisterType<ChatHub>();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
GlobalHost.DependencyResolver = new Autofac.Integration.SignalR.AutofacDependencyResolver(container);
RouteTable.Routes.MapHubs();
我从 autofac 网站获得的依赖左轮手枪;
http://code.google.com/p/autofac/downloads/detail?name=Autofac.SignalR.3.0.0.zip
但我明白了;
从请求实例的范围中看不到带有与“AutofacWebRequest”匹配的标记的范围。这通常表明注册为 per-HTTP 请求的组件正在由 SingleInstance() 组件(或类似场景)请求。在 Web 集成下,始终从 DependencyResolver.Current 或 ILifetimeScopeProvider.RequestLifetime 请求依赖项,而不是从容器本身.