public void ProvidedLifetimeScopeExposed()
        {
            var container = new ContainerBuilder().Build();
            var dependencyResolver = new AutofacDependencyResolver(container);

            Assert.That(dependencyResolver.LifetimeScope, Is.EqualTo(container));
        }
示例#2
0
 private void RegisterAutoFac()
 {
     var builder = new ContainerBuilder();
     builder.RegisterHubs(Assembly.GetExecutingAssembly());
     var container = builder.Build();
     var resolver = new AutofacDependencyResolver(container);
     GlobalHost.DependencyResolver = resolver;
 }
        public void GetServiceReturnsNullForUnregisteredService()
        {
            var container = new ContainerBuilder().Build();
            var resolver = new AutofacDependencyResolver(container);

            var service = resolver.GetService(typeof(object));

            Assert.That(service, Is.Null);
        }
        public void CurrentPropertyExposesTheCorrectResolver()
        {
            var container = new ContainerBuilder().Build();
            var resolver = new AutofacDependencyResolver(container);

            GlobalHost.DependencyResolver = resolver;

            Assert.That(AutofacDependencyResolver.Current, Is.EqualTo(GlobalHost.DependencyResolver));
        }
 /// <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>();
 }
示例#6
0
        private static void RegisterSignalr(Assembly[] assemblies)
        {
            var builder = CreateContainerBuilder();

            builder.RegisterHubs(assemblies);

            var container = builder.Build();
            var resolver  = new SignalrResolver(container);

            GlobalHost.DependencyResolver = resolver;
        }
        public void Configuration(IAppBuilder app)
        {
            var container = new AutofacContainer().Container;

            var resolver = new AutofacDependencyResolver(container);

            app.UseAutofacMiddleware(container);

            app.MapSignalR(new HubConfiguration
            {
                Resolver = resolver
            });

            AddSignalRInjection(container, resolver);
        }
        private static void SetUpSignalR(IAppBuilder app)
        {
            var autofacDependencyResolver = new AutofacDependencyResolver(EndpointConfig.Container);
            var hubConfiguration = new HubConfiguration
                                       {
                                           EnableDetailedErrors = true,
                                           Resolver = autofacDependencyResolver
                                       };
            app.Map(
                "/signalr",
                map =>
                    {
                        map.RunSignalR(hubConfiguration);
                    });

            GlobalHost.DependencyResolver = autofacDependencyResolver;
        }
示例#9
0
        public void Configuration(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <ChatRepository>().As <IChatRepository>().InstancePerDependency();
            builder.RegisterHubs(Assembly.GetExecutingAssembly());

            var container   = builder.Build();
            var depResolver = new Autofac.Integration.SignalR.AutofacDependencyResolver(container);


            var hubConfig = new HubConfiguration()
            {
                Resolver = depResolver
            };

            app.MapSignalR(hubConfig);
        }
示例#10
0
 /// <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>();
 }
示例#11
0
        public void Configuration(IAppBuilder app)
        {
            var handler = JobsHandler.Instance;

            var builder = new ContainerBuilder();

            builder.RegisterHubs(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            builder.RegisterInstance(handler).As <IJobsHandler>();

            var container = builder.Build();

            var signalResolver = new Autofac.Integration.SignalR.AutofacDependencyResolver(container);

            GlobalHost.DependencyResolver = signalResolver;
            DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            app.UseAutofacMiddleware(container);

            app.MapSignalR("/signalr", new HubConfiguration()
            {
                Resolver = signalResolver
            });

            handler.Hosting = new JobScheduler();
            handler.NotificationsBroker.Subscribe(new SignalRNotifier(GlobalHost.ConnectionManager));
            handler.NotificationsBroker.Subscribe(new EmailNotifier());
            handler.NotificationsBroker.Subscribe(new LoggingNotifier());

            handler.AddJob(new NormalJob(), 60);
            handler.AddDailyJob(new NormalJob(), 23);
            handler.AddWeeklyJob(new NormalJob(), DayOfWeek.Monday, 21);
            handler.AddMonthlyJob(new NormalJob(), 0);
        }
        public void CanOverrideDefaultServices()
        {
            var builder = new ContainerBuilder();
            var messageBus = new Mock<IMessageBus>().Object;
            builder.RegisterInstance(messageBus);
            var resolver = new AutofacDependencyResolver(builder.Build());

            var service = resolver.GetService(typeof(IMessageBus));

            Assert.That(service, Is.SameAs(messageBus));
        }
        public void CanResolveDefaultServices()
        {
            var container = new ContainerBuilder().Build();
            var resolver = new AutofacDependencyResolver(container);

            var service = resolver.GetService(typeof(IMessageBus));

            Assert.That(service, Is.InstanceOf<IMessageBus>());
        }
        public void GetServicesReturnsRegisteredService()
        {
            var builder = new ContainerBuilder();
            builder.Register(c => new object());
            var container = builder.Build();
            var resolver = new AutofacDependencyResolver(container);

            var services = resolver.GetServices(typeof(object));

            Assert.That(services.Count(), Is.EqualTo(1));
        }