Exemple #1
0
        private WebAppServer CreateServer()
        {
            var resolver = new WindsorDependencyResolver(_container);
            var server = new WebAppServer(BaseAddress);
            server.HttpConfiguration.DependencyResolver = resolver;
            server.HttpConfiguration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
            server.HttpConfiguration.Routes.MapHttpRoute(
                name: "DefaultAPI",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional });
            server.HttpConfiguration.Routes.MapHttpRoute(
                name: "Default",
                routeTemplate: "{controller}/{action}",
                defaults: new { controller = "Home", action = "Index" });
            //server.HttpConfiguration.MessageHandlers.Add(new FaviconHandler());

            server.StaticFiles.Add("/Scripts", typeof (ScriptsLocator));
            server.HttpConfiguration.MessageHandlers.Add(new StaticFileHandler("Scripts", "text/javascript"));

            var templateConfiguration = new TemplateServiceConfiguration();
            templateConfiguration.Resolver = new EmbeddedTemplateResolver(typeof(ViewResourceLocator));
            templateConfiguration.BaseTemplateType = typeof(CustomTemplateBase<>);
            Razor.SetTemplateService(new TemplateService(templateConfiguration));

            return server;
        }
        public void Should_not_throw_exception_when_multiple_threads_manipulate_the_Dependency_resolver()
        {
            int errorCount = 0;

            for (int i = 0; i < 1000; i++ ) {
                new Thread(() => {
                    var container = new WindsorContainer();
                    _resolver = new WindsorDependencyResolver(container);
                    _resolver.AddDependency(typeof(IDependencyResolver), typeof(WindsorDependencyResolver), DependencyLifetime.Singleton);
                    _resolver.AddDependency(typeof(IWindsorContainer), typeof(WindsorContainer), DependencyLifetime.Singleton);

                    _resolver.AddDependency(typeof(IPipeline), typeof(PipelineRunner), DependencyLifetime.Singleton);

                    try {
                        _resolver.Resolve<IPipeline>();
                    } catch (Exception) {
                        errorCount = errorCount + 1;
                        throw;
                    }

                }).Start();
            }

            Assert.That(errorCount, Is.EqualTo(0), "Some of the requests threw errors meaning that the dependencyresolver is not threadsafe ");
        }
        protected override void Initialize(WindsorContainer container)
        {
            container.Register(Component.For<ITestService>().ImplementedBy<TestService>().Named("1"));
            container.Register(Component.For<ITestService>().ImplementedBy<TestService>().Named("2"));

            this.dependencyResolver = new WindsorDependencyResolver(container);
        }
Exemple #4
0
        private static void InitialiseIoC(ICommandArgs commandArgs)
        {
            var resolver = new WindsorDependencyResolver(commandArgs);

            IoC.InitializeWith(resolver);

            log.Debug("IOC initialised.....");
        }
Exemple #5
0
        public static void ConfigureWindsor(HttpConfiguration configuration)
        {
            _container = new WindsorContainer();
            _container.Install(FromAssembly.This());
            _container.Kernel.Resolver.AddSubResolver(new CollectionResolver(_container.Kernel, true));
            var dependencyResolver = new WindsorDependencyResolver(_container);

            configuration.DependencyResolver = dependencyResolver;
        }
            public override void Setup()
            {
                IWindsorContainer container = new WindsorContainer();
                container.AddComponent("SimpleDependency", typeof(SimpleDependency));
                container.AddComponent("IDependency", typeof(IDependency), typeof(SimpleDependency));
                container.AddComponent("NestedDependency",typeof(NestedDependency));

                _dependencyResolver = new WindsorDependencyResolver(container);
            }
            public override void Setup()
            {
                IWindsorContainer container = new WindsorContainer();

                container.AddComponent("SimpleDependency", typeof(SimpleDependency));
                container.AddComponent("IDependency", typeof(IDependency), typeof(SimpleDependency));
                container.AddComponent("NestedDependency", typeof(NestedDependency));

                _dependencyResolver = new WindsorDependencyResolver(container);
            }
Exemple #8
0
        public static IWindsorContainer ConfigureWindsor(HttpConfiguration configuration)
        {
            var container = CastleInstaller.Install();

            var dependencyResolver = new WindsorDependencyResolver(container);

            configuration.DependencyResolver = dependencyResolver;

            return(container);
        }
Exemple #9
0
        /// <summary>The configure windsor.</summary>
        /// <param name="configuration">The configuration.</param>
        public static void ConfigureWindsor(HttpConfiguration configuration)
        {
            var container = Ragolo.Core.IoC.IocHelper.Instance;

            container.Install(new ValidadoresInstaller());
            container.Install(FromAssembly.This(), new ModuloRepositorios());
            var dependencyResolver = new WindsorDependencyResolver(container.GetContainer());

            configuration.DependencyResolver = dependencyResolver;
        }
Exemple #10
0
        public void then_it_should_not_error()
        {
            var windsorContainer = new WindsorContainer();

            windsorContainer.Register(Component.For <IDependencyResolver>().ImplementedBy <FakeResolver>());
            var windsorDependencyResolver = new WindsorDependencyResolver(windsorContainer);

            windsorContainer.Resolve <IDependencyResolver>().ShouldBeAssignableTo <FakeResolver>();
            windsorContainer.Resolve <IModelDrivenDependencyRegistration>().ShouldBeAssignableTo <WindsorDependencyResolver>();
        }
        public void WindsorResolverShouldNotResolveNonRegisteredDummyRepositoryTest()
        {
            using (var container = new WindsorContainer())
            {
                var resolver = new WindsorDependencyResolver(container);
                var instance = resolver.GetService(typeof(IDummyRepository));

                Assert.IsNull(instance);
            }
        }
Exemple #12
0
        private static void BootstrapContainer(HttpConfiguration configuration)
        {
            container = new WindsorContainer()
                        .Install(FromAssembly.This());
            container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel));

            var dependencyResolver = new WindsorDependencyResolver(container);

            configuration.DependencyResolver = dependencyResolver;
        }
Exemple #13
0
        private void InstallWindsorContainerInstallers(HttpConfiguration configuration)
        {
            container.Install(FromAssembly.This());
            container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true));
            var dependencyResolver = new WindsorDependencyResolver(container);

            configuration.DependencyResolver = dependencyResolver;

            //container.Register(Component.For<IWindsorContainer>().Instance(container).LifeStyle.Singleton);
            //container.Install(FromAssembly.InDirectory(new AssemblyFilter(HttpRuntime.BinDirectory, "*.dll")));
        }
Exemple #14
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            IDependencyResolver resolver = new WindsorDependencyResolver(WebUIContainerFactory.Current());

            DependencyResolver.SetResolver(resolver);
        }
Exemple #15
0
        private static void RegisterDependencies()
        {
            WindsorContainer
            .Install(
                new CustomizedWebApiInstaller(GlobalConfiguration.Configuration, typeof(MvcApplication).Assembly),
                new ControllerInstaller()
                );

            var windsorDependencyResolver = new WindsorDependencyResolver(WindsorContainer);

            GlobalConfiguration.Configuration.DependencyResolver = windsorDependencyResolver;
        }
Exemple #16
0
        public void GetService_WhenTheServiceIsRegisteredInTheContainer_ReturnTheService()
        {
            var stubDependency = MockRepository.GenerateStub <IControllerFactory>();
            var mockKernel     = new WindsorContainer();

            mockKernel.Register(Component.For(typeof(IControllerFactory)).Instance(stubDependency));

            var resolver           = new WindsorDependencyResolver(null, mockKernel.Kernel);
            var resolvedDependency = resolver.GetService(typeof(IControllerFactory));

            Assert.AreEqual(stubDependency, resolvedDependency);
        }
Exemple #17
0
        public static void ConfigureWindsor(HttpConfiguration configuration)
        {
            container = new WindsorContainer();
            container.Install(FromAssembly.This());
            container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true));
            var dependencyResolver = new WindsorDependencyResolver(container);

            configuration.DependencyResolver = dependencyResolver;

            configuration.Services.Replace(typeof(IHttpControllerSelector), new CustomControllerSelector(configuration));
            configuration.Services.Replace(typeof(IHttpActionSelector), new CustomActionSelector());
        }
Exemple #18
0
        protected void Application_Start()
        {
            var container = new WindsorContainer();

            container.Install(FromAssembly.This());
            container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true));
            var dependencyResolver = new WindsorDependencyResolver(container);

            GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver;

            GlobalConfiguration.Configure(c => WebApiConfig.Register(c, container));
        }
        public void Provided_logger_is_not_overridden_by_defaults()
        {
            var container = new WindsorContainer();
            container.Register(Component.For<ILogger>().ImplementedBy<MyLogger>());
            var dependencyResolver = new WindsorDependencyResolver(container);
            var registrar = new TestDependencyRegistrar();
            registrar.RegisterLogging(dependencyResolver);

            var logger = container.Resolve(typeof(ILogger));

            Assert.That(logger, Is.InstanceOf(typeof(MyLogger)));
        }
Exemple #20
0
        private static void BootstrapContainer()
        {
            container = new WindsorContainer()
                        .Install(FromAssembly.This());
            var controllerFactory = new WindsorControllerFactory(container);

            ControllerBuilder.Current.SetControllerFactory(controllerFactory);

            var resolver = new WindsorDependencyResolver(container);

            DependencyResolver.SetResolver(resolver);
        }
        public void WindsorResolveSingleInstance()
        {
            var container  = new WindsorContainer();
            var registered = new Registered();

            container.Register(Component.For <Registered>().Instance(registered));

            var resolver = new WindsorDependencyResolver(container);

            var resolved = (Registered)resolver.GetInstance(typeof(Registered));

            Assert.That(resolved, Is.EqualTo(registered));
        }
 public void InitializeTest()
 {
     IKernel mockKernel = MockRepository.GenerateMock<IKernel>();
     IWindsorContainer mockWindsorContainer = MockRepository.GenerateMock<IWindsorContainer>();
     mockKernel.Expect(m => m.HasComponent(typeof(int))).Return(true);
     mockKernel.Expect(m => m.HasComponent(typeof(string))).Return(true);
     mockWindsorContainer.Expect(m => m.Resolve(typeof(int))).Return(1);
     mockWindsorContainer.Expect(m => m.ResolveAll(typeof(int))).Return(new[] { 1, 2, 3 });
     mockWindsorContainer.Expect(m => m.Resolve(typeof(string))).Return("1");
     mockWindsorContainer.Expect(m => m.ResolveAll(typeof(string))).Return(new[] { "1", "2", "3" });
     mockWindsorContainer.Expect(m => m.Kernel).Return(mockKernel);
     Target = new WindsorDependencyResolver(mockWindsorContainer);
 }
        /// <summary>
        /// Runs all installers within this assembly and wires up WebApi to use the castle windsor dependency injection container
        /// </summary>
        /// <param name="config">The HTTP configuration.</param>
        /// <returns>
        /// The dependency injection container
        /// </returns>
        private static IWindsorContainer RegisterWindsorContainer(HttpConfiguration config)
        {
            // Create the windsor container and run all installers in the application
            IWindsorContainer container = new WindsorContainer().Install(FromAssembly.InThisApplication());

            // Wire up webapi to use the windsor resolver for dependency injection
            var resolver = new WindsorDependencyResolver(container.Kernel);

            config.DependencyResolver = resolver;
            GlobalConfiguration.Configuration.DependencyResolver = resolver;

            return(container);
        }
        public void WindsorResolverShouldResolveRegisteredDummyRepositoryTest()
        {
            using (var container = new WindsorContainer())
            {
                container.Register(
                    Component.For <IDummyRepository>().Instance(new InMemoryDummyRepository()));

                var resolver = new WindsorDependencyResolver(container);
                var instance = resolver.GetService(typeof(IDummyRepository));

                Assert.IsNotNull(instance);
            }
        }
Exemple #25
0
        public void InitializeTest()
        {
            IKernel           mockKernel           = MockRepository.GenerateMock <IKernel>();
            IWindsorContainer mockWindsorContainer = MockRepository.GenerateMock <IWindsorContainer>();

            mockKernel.Expect(m => m.HasComponent(typeof(int))).Return(true);
            mockKernel.Expect(m => m.HasComponent(typeof(string))).Return(true);
            mockWindsorContainer.Expect(m => m.Resolve(typeof(int))).Return(1);
            mockWindsorContainer.Expect(m => m.ResolveAll(typeof(int))).Return(new[] { 1, 2, 3 });
            mockWindsorContainer.Expect(m => m.Resolve(typeof(string))).Return("1");
            mockWindsorContainer.Expect(m => m.ResolveAll(typeof(string))).Return(new[] { "1", "2", "3" });
            mockWindsorContainer.Expect(m => m.Kernel).Return(mockKernel);
            Target = new WindsorDependencyResolver(mockWindsorContainer);
        }
Exemple #26
0
        public static void ConfigureIocContainer(HttpConfiguration globalConfiguration)
        {
            var container = new WindsorContainer();

            container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel, true));

            container.Install(FromAssembly.Containing <DomainInstaller>()).
            Install(FromAssembly.Containing <CommonInstaller>()).
            Install(FromAssembly.This());

            var dependencyResolver = new WindsorDependencyResolver(container.Kernel);

            GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver;
        }
Exemple #27
0
        public void GetService_WhenTheServiceIsNotRegisteredInTheContainer_AskTheResolutionToTheDefaultMvcResolver()
        {
            var stubDependency      = MockRepository.GenerateStub <IControllerFactory>();
            var mockDefaultResolver = MockRepository.GenerateMock <IDependencyResolver>();

            mockDefaultResolver.Stub(s => s.GetService(typeof(IControllerFactory))).Return(stubDependency);
            IKernel stubKernel = new WindsorContainer().Kernel;

            var resolver           = new WindsorDependencyResolver(mockDefaultResolver, stubKernel);
            var resolvedDependency = resolver.GetService(typeof(IControllerFactory));

            mockDefaultResolver.AssertWasCalled(m => m.GetService(typeof(IControllerFactory)));
            Assert.AreEqual(stubDependency, resolvedDependency);
        }
Exemple #28
0
        public void Provided_logger_is_not_overridden_by_defaults()
        {
            var container = new WindsorContainer();

            container.Register(Component.For <ILogger>().ImplementedBy <MyLogger>());
            var dependencyResolver = new WindsorDependencyResolver(container);
            var registrar          = new TestDependencyRegistrar();

            registrar.RegisterLogging(dependencyResolver);

            var logger = container.Resolve(typeof(ILogger));

            Assert.That(logger, Is.InstanceOf(typeof(MyLogger)));
        }
Exemple #29
0
        public void GetServices_WhenTheServicesIsNotRegisteredInContainerEitherInDefaultResolver_ReturnAnEmptyEnumerator()
        {
            var stubDefaultResolver = MockRepository.GenerateStub <IDependencyResolver>();

            stubDefaultResolver.Stub(s => s.GetServices(Arg <Type> .Is.Anything)).Return(new object[] {});
            var stubKernel = MockRepository.GenerateStub <IKernel>();

            stubKernel.Stub(s => s.ResolveAll(Arg <Type> .Is.Anything)).Return(new object[] {});

            var resolver = new WindsorDependencyResolver(stubDefaultResolver, stubKernel);
            var services = resolver.GetServices(typeof(IControllerFactory));

            Assert.AreEqual(0, services.Count());
        }
        public static void Setup(HttpConfiguration configuration)
        {
            _container = new WindsorContainer();
            _container.Install(FromAssembly.This());
            _container.Kernel.Resolver.AddSubResolver(new CollectionResolver(_container.Kernel, true));
            var dependencyResolver = new WindsorDependencyResolver(_container);

            configuration.DependencyResolver = dependencyResolver;

            Mapper.Initialize(cfg =>
                              cfg.AddProfiles(new[] {
                typeof(ApiServiceMappers)
            })
                              );
        }
Exemple #31
0
        /// <summary>
        /// Configures the windsor configuration.
        /// </summary>
        private void ConfigureWindsorConfig()
        {
            _container = new WindsorContainer();
            _container.Install(FromAssembly.This());
            //GlobalConfiguration.Configuration.Services.Replace(
            //    typeof(DefaultControllerFactory),
            //    new WindsorCompositionRoot(_container.Kernel));
            var controllerFactory = new WindsorCompositionRoot(_container.Kernel);

            ControllerBuilder.Current.SetControllerFactory(controllerFactory);
            _container.Kernel.Resolver.AddSubResolver(new CollectionResolver(_container.Kernel, true));
            var dependencyResolver = new WindsorDependencyResolver(_container);

            GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver;
        }
Exemple #32
0
        public static void ConfigureWindsor(HttpConfiguration configuration)
        {
            _container = new WindsorContainer();

            _container.Install(FromAssembly.This());
            _container.Install(FromAssembly.Named("Cherries.Services.Bootstrapper"));
            _container.Install(FromAssembly.Named("TFI.BusinessLogic.Bootstraper"));

            _container.Kernel.Resolver.AddSubResolver(new CollectionResolver(_container.Kernel, true));

            var dependencyResolver = new WindsorDependencyResolver(_container);

            configuration.DependencyResolver = dependencyResolver;
            GlobalHost.DependencyResolver    = new SignalrWindsorDependencyResolver(_container);
        }
        private static IWindsorContainer CreateTestDependencies()
        {
            var result = new WindsorContainer();
            result.AddComponent<ISparkExtensionFactory, CodecSparkExtensionFactory>();
            result.AddComponent<ISparkElementTransformerService, SparkElementTransformerService>();
            result.AddComponent<IElementTransformerService, ElementTransformerService>();
            result.AddComponent<ISpecificationProvider, DefaultSpecification>();

            // openrasta stuff
            var resolver = new WindsorDependencyResolver(result);
            resolver.AddDependency(typeof(IUriResolver), typeof(TestUriResolver), DependencyLifetime.Singleton);
            resolver.AddDependency(typeof(ICommunicationContext), typeof(TestCommunicationContext),DependencyLifetime.Singleton);
            DependencyManager.SetResolver(resolver);
            return result;
        }
Exemple #34
0
        public void GetServices_WhenTheServicesIsRegisteredInTheDefaultResolver_ReturnTheService()
        {
            var stubDependency      = MockRepository.GenerateStub <IControllerFactory>();
            var stubDefaultResolver = MockRepository.GenerateStub <IDependencyResolver>();

            stubDefaultResolver.Stub(s => s.GetServices(typeof(IControllerFactory))).Return(new[] { stubDependency });
            var stubKernel = MockRepository.GenerateStub <IKernel>();

            stubKernel.Stub(s => s.ResolveAll(Arg <Type> .Is.Anything)).Return(new object[] { });

            var resolver = new WindsorDependencyResolver(stubDefaultResolver, stubKernel);
            var services = resolver.GetServices(typeof(IControllerFactory));

            Assert.AreEqual(1, services.Count());
            Assert.IsTrue(services.Contains(stubDependency));
        }
Exemple #35
0
        public static void ConfigureWindsor(HttpConfiguration configuration)
        {
            //Se inicializa contenedor Windsor
            container = new WindsorContainer();
            //Se realiza registro de dependecias en contenedor
            container.Register(Component.For <IAplicacionClientes>().ImplementedBy <AplicacionClientes>()
                               .LifestylePerThread());
            container.Register(Component.For <IServiciosClientes>().ImplementedBy <ServicioClientes>()
                               .LifestylePerThread());
            container.Install(FromAssembly.This());

            container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true));
            var dependencyResolver = new WindsorDependencyResolver(container);

            configuration.DependencyResolver = dependencyResolver;
        }
        private void BootstrapContainer()
        {
            _container = new WindsorContainer();
            _container.AddFacility <TypedFactoryFacility>();
            _container.Install(FromAssembly.This());

            // MVC Dependency Resolution
            var controllerFactory = new CastleControllerFactory(_container.Kernel);

            ControllerBuilder.Current.SetControllerFactory(controllerFactory);

            // WebApi Dependency Resolution
            var dependencyResolver = new WindsorDependencyResolver(_container);

            GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver;
        }
Exemple #37
0
        public void GetServices_WhenTheServicesIsRegisteredInBothTheContainerAndTheDefaultResolver_ReturnServicesFromBothResolversWithoutDuplications()
        {
            var stubDependency      = MockRepository.GenerateStub <IControllerFactory>();
            var mockDefaultResolver = MockRepository.GenerateMock <IDependencyResolver>();

            mockDefaultResolver.Stub(s => s.GetServices(typeof(IControllerFactory))).Return(new[] { stubDependency });
            var mockKernel = MockRepository.GenerateMock <IKernel>();

            mockKernel.Stub(s => s.ResolveAll(typeof(IControllerFactory))).Return(new [] { stubDependency });

            var resolver = new WindsorDependencyResolver(mockDefaultResolver, mockKernel);
            var services = resolver.GetServices(typeof(IControllerFactory));

            Assert.AreEqual(1, services.Count());
            Assert.IsTrue(services.Contains(stubDependency));
        }
Exemple #38
0
        protected void Application_Start()
        {
            // Main container first
            var mainContainer = CreateContainer();

            // Hook the main container into the web api dependency resolver
            var dependencyResolver = new WindsorDependencyResolver(mainContainer);
            var configuration      = GlobalConfiguration.Configuration;

            configuration.DependencyResolver = dependencyResolver;
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(mainContainer.Kernel));

            // Wire up the payment queue to use mainContainer
            var paymentQueue = new PaymentQueue(
                Configure
                .With(new CastleWindsorContainerAdapter(CreateContainer()))
                .Transport(t => t.UseSqlServerAsOneWayClient("server=.;database=Scratch;trusted_connection=true"))
                .Routing(r => r.TypeBased().Map <Payment>("PaymentQueue"))
                .Start()
                );



            // Need another container for the orders queue
            var orderQueue = new OrderQueue(
                Configure
                .With(new CastleWindsorContainerAdapter(CreateContainer()))
                .Transport(t => t.UseRabbitMqAsOneWayClient("amqp://localhost"))
                .Routing(r => r.TypeBased().Map <Order>("OrderQueue"))
                .Start()
                );

            // Register our custom queues in every container... not sure this is going to work, should
            foreach (var container in _containers)
            {
                container.Register(
                    Component.For <PaymentQueue>().Instance(paymentQueue),
                    Component.For <OrderQueue>().Instance(orderQueue)
                    );
            }



            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
Exemple #39
0
        public static void InstallProduct(HttpConfiguration configuration)
        {
            container = new WindsorContainer();
            container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true));
            db = new ExportDataContext();

            container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true));

            container.Register(
                               Component.For<IExportDataRepository>().Instance(new ExportDataRepository(db)).LifestyleScoped(),
                               Component.For<ExportDataController>().ImplementedBy<ExportDataController>().LifestyleScoped(),
                               Component.For<IPDFImageRepository>().Instance(new PDFImageRepository(db)).LifestyleScoped(),
                               Component.For<PdfImageController>().ImplementedBy<PdfImageController>().LifestyleScoped()
                    );

            var dependencyResolver = new WindsorDependencyResolver(container.Kernel);
            configuration.DependencyResolver = dependencyResolver;
        }
        static void Main(string[] args)
        {
            using (system = ActorSystem.Create("akka-performance-demo"))
            {
                var registeredMonitor = ActorMonitoringExtension.RegisterMonitor(system, new Monitor());

                IWindsorContainer container = new WindsorContainer();
                container.Register( Component.For<IInterceptor>().
                                    ImplementedBy<MonitorInterceptor>().
                                    Named("monitorInterceptor"),
                                    Component.For<HelloActor>().
                                    LifestyleTransient().
                                    Interceptors(InterceptorReference.ForKey("monitorInterceptor")).
                                    Anywhere);

                WindsorDependencyResolver propsResolver =
                        new WindsorDependencyResolver(container, system);

                var hello = system.ActorOf(propsResolver.Create<HelloActor>(), "Worker1");

                hello.Tell("What's Up");
                hello.Tell("Goodbye");

                var count = 20;
                while (count >= 0)
                {
                    ActorMonitoringExtension.Monitors(system).IncrementDebugsLogged();
                    Console.WriteLine("Logging debug...");
                    Thread.Sleep(100);
                    count--;
                }

                while (ManualResetEvent.WaitOne())
                {
                    Console.WriteLine("Shutting down...");
                    system.Shutdown();
                    Console.WriteLine("Shutdown complete");
                    Console.WriteLine("Press any key to exit");
                    Console.ReadKey();
                    return;
                }

            }
        }
        private static void Main(string[] args)
        {
            var container = new WindsorContainer();

            container.Register(Component.For<ITrendingMovieAnalyzer>().ImplementedBy<SimpleTrendingMovieAnalyzer>());
            container.Register(Component.For<TrendingMoviesActor>());

            MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem");

            IDependencyResolver resolver = new WindsorDependencyResolver(container, MovieStreamingActorSystem);

            MovieStreamingActorSystem.ActorOf(Props.Create<PlaybackActor>(), "Playback");

            do
            {
                ShortPause();

                Console.WriteLine();
                Console.WriteLine("enter a command and hit enter");

                var command = Console.ReadLine();

                if (command.StartsWith("play"))
                {
                    int userId = int.Parse(command.Split(',')[1]);
                    string movieTitle = command.Split(',')[2];

                    var message = new PlayMovieMessage(movieTitle, userId);
                    MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
                }

                if (command.StartsWith("stop"))
                {
                    int userId = int.Parse(command.Split(',')[1]);

                    var message = new StopMovieMessage(userId);
                    MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
                }

            } while (true);
        }
Exemple #42
0
        private static void WithHashPool()
        { using (var system = ActorSystem.Create("MySystem"))
            {
                IWindsorContainer container = new WindsorContainer();
                container.Register(Component.For<TypedWorker>().Named("TypedWorker").LifestyleTransient());



                var propsResolver =
                    new WindsorDependencyResolver(container, system);

                var router = system.ActorOf(system.DI().Props<TypedWorker>().WithRouter(FromConfig.Instance), "router1");

                Task.Delay(500).Wait();
                Console.WriteLine("Sending Messages");
                for (var i = 0; i < 5; i++)
                {
                    for (var j = 0; j < 7; j++)
                    {

                        var msg = new TypedActorMessage { Id = j, Name = Guid.NewGuid().ToString() };
                        var ms = new AnotherMessage { Id = j, Name = msg.Name };

                        var envelope = new ConsistentHashableEnvelope(ms, msg.Id);

                        router.Tell(msg);
                        router.Tell(envelope);

                    }
                }
                Console.WriteLine("Hit Enter to exit");
                Console.ReadLine();
            }

            
        }
 public override void RegisterServices(IWindsorContainer container)
 {
     resolver = new WindsorDependencyResolver(container);
     base.RegisterServices(container);
 }
        protected override void Before_each_spec()
        {
            var resolver = new WindsorDependencyResolver(new CommandArgsDouble("horn"));

            global::IoC.InitializeWith(resolver);
        }
 protected override void Initialize(WindsorContainer container)
 {
     this.dependencyResolver = new WindsorDependencyResolver(container);
 }
 public void ForCoverage()
 {
     IWindsorContainer container = new WindsorDependencyResolver().Container;
 }
 public void Setup()
 {
     _container = MockRepository.GenerateMock<IWindsorContainer>();
     _resolver = new WindsorDependencyResolver(_container);
 }
Exemple #48
0
        public void WindsorResolveSingleInstance()
        {
            var container = new WindsorContainer();
            var registered = new Registered();
            container.Register(Component.For<Registered>().Instance(registered));

            var resolver = new WindsorDependencyResolver(container);

            var resolved = (Registered) resolver.GetInstance(typeof (Registered));

            Assert.That(resolved, Is.EqualTo(registered));
        }
 public WindsorDependencyResolverAccessor()
 {
     Resolver = new WindsorDependencyResolver(_container);
 }