/// <summary> /// 构建服务并设置SignalR平台的Resolver /// </summary> /// <param name="services">服务映射信息集合</param> /// <param name="assemblies">要检索的程序集集合</param> protected override IServiceProvider BuildAndSetResolver(IServiceCollection services, Assembly[] assemblies) { ContainerBuilder builder = new ContainerBuilder(); builder.RegisterHubs().AsSelf().PropertiesAutowired(); builder.Populate(services); IContainer container = builder.Build(); IDependencyResolver resolver = new AutofacDependencyResolver(container); GlobalHost.DependencyResolver = resolver; return resolver.Resolve<IServiceProvider>(); }
/// <summary> /// 构建服务并设置SignalR平台的Resolver /// </summary> /// <param name="services">服务映射信息集合</param> /// <param name="assemblies">要检索的程序集集合</param> protected override IServiceProvider BuildAndSetResolver(IServiceCollection services, Assembly[] assemblies) { ContainerBuilder builder = new ContainerBuilder(); builder.RegisterHubs(assemblies).AsSelf().PropertiesAutowired(); builder.RegisterLifetimeHubManager(); builder.Populate(services); IContainer container = builder.Build(); IDependencyResolver resolver = new AutofacDependencyResolver(container); GlobalHost.DependencyResolver = resolver; SignalRIocResolver.LifetimeResolveFunc = type => { ILifetimeScope scope = CallContext.LogicalGetData(LifetimeHubManager.LifetimeScopeKey) as ILifetimeScope; if (scope == null) { return null; } return scope.ResolveOptional(type); }; return resolver.Resolve<IServiceProvider>(); }