コード例 #1
0
        /// <summary>
        /// </summary>
        /// <param name="configuration"></param>
        private void ConfigureWindsor(HttpConfiguration configuration)
        {
            // Castle Windsor setup
            _container = new WindsorContainer();
            //_container.Install(FromAssembly.This()); -- would normally call out to "ApiControllersInstaller", but we handle this with the Register() call below
            //type.Name.EndsWith("Service")) -- would be service if we were using WCF.

            _container.Register(Component.For<IWindsorContainer>().Instance(_container)); // Not a fan of this as it passes a reference to the conatiner itself, but it is necessary for the RequestProcessor to work.

            _container.Register(Classes.FromThisAssembly()
                .Where(type => type.Name.EndsWith("Controller"))
                .WithServiceDefaultInterfaces()
                .LifestylePerWebRequest()
                .Configure(component => component.Named(component.Implementation.FullName)));
            new CompositionRoot().ComposeApplication(_container); // Calls out to Infrastructure project's \DependencyInjection\Installers

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


            var dependencyResolver = new WindsorDependencyResolver(_container);
            configuration.DependencyResolver = dependencyResolver;
        }
コード例 #2
0
        /// <summary>
        /// </summary>
        /// <param name="configuration"></param>
        private void ConfigureWindsor(HttpConfiguration configuration)
        {
            // Castle Windsor setup
            _container = new WindsorContainer();
            //_container.Install(FromAssembly.This()); -- would normally call out to "ApiControllersInstaller", but we handle this with the Register() call below
            //type.Name.EndsWith("Service")) -- would be service if we were using WCF.

            _container.Register(Component.For <IWindsorContainer>().Instance(_container)); // Not a fan of this as it passes a reference to the conatiner itself, but it is necessary for the RequestProcessor to work.

            _container.Register(Classes.FromThisAssembly()
                                .Where(type => type.Name.EndsWith("Controller"))
                                .WithServiceDefaultInterfaces()
                                .LifestylePerWebRequest()
                                .Configure(component => component.Named(component.Implementation.FullName)));
            new CompositionRoot().ComposeApplication(_container); // Calls out to Infrastructure project's \DependencyInjection\Installers

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


            var dependencyResolver = new WindsorDependencyResolver(_container);

            configuration.DependencyResolver = dependencyResolver;
        }