Beispiel #1
0
        protected void Application_Start()
        {
            XmlConfigurator.Configure();
            IWindsorContainer ioc = new WindsorContainer();
            ioc.AddFacility<FactorySupportFacility>();

            ioc.Register(Component.For<ValidatorEngine>().UsingFactoryMethod(CreateValidatorEngine));
            ioc.Register(Component.For<Nexida.Infrastructure.IValidator>().ImplementedBy<NHibernateValidator>());

            ioc.Register(Component.For<ISessionFactory>().UsingFactoryMethod(CreateSessionFactory));
            ioc.Register(Component.For<IConversationFactory>().UsingFactoryMethod(CreateConversationFactory));
            ioc.Register(Component.For<IConversation>().UsingFactoryMethod(CreateConversation).LifeStyle.PerWebRequest);

            ioc.Register(Component.For<IMappingEngine>().UsingFactoryMethod(MappingEngineBuilder.Build));

            ioc.Register(AllTypes.FromAssemblyContaining<CustomerStringConverter>().BasedOn(typeof(IStringConverter<>)).WithService.Base());
            ioc.Register(AllTypes.FromAssemblyContaining<CustomerFactory>().BasedOn(typeof(IFactory<>)).WithService.Base());
            ioc.Register(AllTypes.FromAssemblyContaining<CustomerRepository>().BasedOn<IRepository>());

            ioc.RegisterControllers(typeof(NsCustomerController).Assembly);
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(ioc));

            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
            ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
            ModelBinders.Binders.DefaultBinder = new DefaultToNullModelBinder(ModelBinders.Binders.DefaultBinder);
            ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(ioc));
        }
Beispiel #2
0
        /// <summary>
        /// Instantiate the container and add all Controllers that derive from
        /// WindsorController to the container.  Also associate the Controller
        /// with the WindsorContainer ControllerFactory.
        /// </summary>
        protected virtual void InitializeServiceLocator()
        {
            var container = new WindsorContainer();

            // Initialize MVC application
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
            container.RegisterControllers(typeof(HomeController).Assembly);
            ComponentRegistrar.AddComponentsTo(container);

            // Initialize WebApi
            container.Register(AllTypes.FromAssembly(typeof(HomeController).Assembly)
                               .BasedOn <ApiController>()
                               .If(r => r.Name.EndsWith("Controller"))
                               .LifestyleTransient());

            GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator),
                                                               new WindsorCompositionRoot(container));

            GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(container);

            // Setup service locator
            var windsorServiceLocator = new WindsorServiceLocator(container);

            DomainEvents.ServiceLocator = windsorServiceLocator;
            ServiceLocator.SetLocatorProvider(() => windsorServiceLocator);
        }
 public void RegisterControllers_uses_lifestyle_transient()
 {
     var sut = new WindsorContainer();
     sut.Install(new WpfInstaller());
     sut.RegisterControllers(Assembly.GetAssembly(typeof(TerminalController)));
     Assert.AreNotSame(sut.Resolve(typeof (TerminalController)), sut.Resolve(typeof (TerminalController)));
     sut.Dispose();
 }
Beispiel #4
0
        /// <summary>
        /// Instantiate the container and add all Controllers that derive from
        /// WindsorController to the container.  Also associate the Controller
        /// with the WindsorContainer ControllerFactory.
        /// </summary>
        protected virtual void InitializeServiceLocator()
        {
            IWindsorContainer container = new WindsorContainer();

            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
            container.RegisterControllers(typeof(BlogController).Assembly);
            ComponentRegistrar.AddComponentsTo(container);
            ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
        }
        /// <summary>
        /// Instantiate the container and add all Controllers that derive from 
        /// WindsorController to the container.  Also associate the Controller 
        /// with the WindsorContainer ControllerFactory.
        /// </summary>
        protected virtual void InitializeServiceLocator() {
            IWindsorContainer container = new WindsorContainer();
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));

            container.RegisterControllers(typeof(HomeController).Assembly);
            ComponentRegistrar.AddComponentsTo(container);

            ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
        }
Beispiel #6
0
        private static IWindsorContainer InitializeServiceLocator()
        {
            IWindsorContainer container = new WindsorContainer();
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));

            container.RegisterControllers(typeof(HomeController).Assembly);
            ComponentRegistrar.AddComponentsTo(container);

            //ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));

            return container;
        }
Beispiel #7
0
        private void Bootstrapper()
        {
            IWindsorContainer container = new WindsorContainer();
            // IFooService with DummyFooService
            container.Register(AllTypes.Pick().FromAssembly(typeof(MvcApplication).Assembly)
                    .WithService.FirstInterface());
            // Controller
            container.RegisterControllers(typeof(HomeController).Assembly);

            // Set the controller factory
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
        }
Beispiel #8
0
        private static IWindsorContainer InitializeServiceLocator()
        {
            IWindsorContainer container = new WindsorContainer();

            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));

            container.RegisterControllers(typeof(HomeController).Assembly);
            ComponentRegistrar.AddComponentsTo(container);

            ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));

            return(container);
        }
Beispiel #9
0
        /// <summary>
        /// Instantiate the container and add all Controllers that derive from
        /// WindsorController to the container.  Also associate the Controller
        /// with the WindsorContainer ControllerFactory.
        /// </summary>
        protected virtual void InitializeWindsor()
        {
            if (_container == null)
            {
                _container = new WindsorContainer();

                ControllerBuilder.Current.SetControllerFactory(new MvcContrib.Castle.WindsorControllerFactory(Container));

                _container
                .RegisterControllers(typeof(HomeController).Assembly)
                .AddComponent <IService, Service>();
            }
        }
Beispiel #10
0
        /// <summary>
        /// Instantiate the container and add all Controllers that derive from 
        /// WindsorController to the container.  Also associate the Controller 
        /// with the WindsorContainer ControllerFactory.
        /// </summary>
        protected virtual void InitializeWindsor()
        {
            if (_container == null)
            {
                _container = new WindsorContainer();

                ControllerBuilder.Current.SetControllerFactory(new MvcContrib.Castle.WindsorControllerFactory(Container));

                _container
                    .RegisterControllers(typeof(HomeController).Assembly)
                    .AddComponent<IService, Service>();
            }
        }
Beispiel #11
0
        private void Bootstrapper()
        {
            IWindsorContainer container = new WindsorContainer();

            // IFooService with DummyFooService
            container.Register(AllTypes.Pick().FromAssembly(typeof(MvcApplication).Assembly)
                               .WithService.FirstInterface());
            // Controller
            container.RegisterControllers(typeof(HomeController).Assembly);

            // Set the controller factory
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
        }
Beispiel #12
0
 /// <summary>
 /// Instantiate the container and add all Controllers that derive from 
 /// WindsorController to the container.  Also associate the Controller 
 /// with the WindsorContainer ControllerFactory.
 /// </summary>
 protected virtual void InitializeWindsor()
 {
     if (_container == null)
     {
         _container = new WindsorContainer();
         ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(Container));
         _container
             .RegisterControllers(typeof(HomeController).Assembly)
             .AddComponent<IService, Service>()
             .AddComponent<IPersonRepository, PersonInMemoryRepository>()
         .AddComponentLifeStyle<ISessionProvider, SessionProvider>(LifestyleType.Singleton);
         _container.AddComponentLifeStyle<IUnitOfWork, UnitOfWork>(LifestyleType.PerWebRequest);
     }
 }
Beispiel #13
0
        /// <summary>
        /// Instantiate the container and add all Controllers that derive from 
        /// WindsorController to the container.  Also associate the Controller 
        /// with the WindsorContainer ControllerFactory.
        /// </summary>
        protected virtual void InitializeWindsor()
        {
            if (_container == null)
            {
                ModelBinders.Binders.DefaultBinder = new SubControllerBinder();

                _container = new WindsorContainer();

                // Add our singleton NVelocityViewFactory
                Type[] assemblyTypes = Assembly.GetExecutingAssembly().GetTypes();

                _container.RegisterControllers(assemblyTypes);
                ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(_container));
            }
        }
Beispiel #14
0
        private static void InitializeIocContainer()
        {
            Container = new WindsorContainer();

            // repositories
            Container.AddComponent <ILanguageRepository, LanguageRepository>();
            Container.AddComponent <ITextRepository, TextRepository>();
            Container.AddComponent <IChannelRepository, ChannelRepository>();
            Container.AddComponent <ITemplateRepository, TemplateRepository>();
            Container.AddComponent <IPostingRepository, PostingRepository>();
            Container.AddComponent <IRegistrationRepository, RegistrationRepository>();
            Container.AddComponent <IWishRepository, WishRepository>();

            // services
            Container.AddComponent <ISessionProvider, SessionProvider>();
            Container.AddComponent <ITextService, TextService>();
            Container.AddComponent <IChannelService, ChannelService>();

            // controllers
            Container.RegisterControllers(Assembly.GetCallingAssembly());
        }
        private static void InitializeIocContainer()
        {
            Container = new WindsorContainer();

            // repositories
            Container.AddComponent<ILanguageRepository,LanguageRepository>();
            Container.AddComponent<ITextRepository, TextRepository>();
            Container.AddComponent<IChannelRepository, ChannelRepository>();
            Container.AddComponent<ITemplateRepository, TemplateRepository>();
            Container.AddComponent<IPostingRepository, PostingRepository>();
            Container.AddComponent<IRegistrationRepository, RegistrationRepository>();
            Container.AddComponent<IWishRepository, WishRepository>();

            // services
            Container.AddComponent<ISessionProvider, SessionProvider>();
            Container.AddComponent<ITextService,TextService>();
            Container.AddComponent<IChannelService, ChannelService>();

            // controllers
            Container.RegisterControllers(Assembly.GetCallingAssembly());
        }
Beispiel #16
0
        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure();
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);

            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
            ModelValidatorProviders.Providers.Add(new NHibernateValidatorProvider()); //Server side validation provider

            ModelBinders.Binders.DefaultBinder = new SharpModelBinder();

            IWindsorContainer container = new WindsorContainer();
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
            container.RegisterControllers(typeof(SimpleStore.Web.Controllers.HomeController).Assembly);
            //Generic Repositories
            container.AddComponent("entityDuplicateChecker",
                typeof(IEntityDuplicateChecker), typeof(EntityDuplicateChecker));
            container.AddComponent("repositoryType",
                typeof(IRepository<>), typeof(Repository<>));
            container.AddComponent("nhibernateRepositoryType",
                typeof(INHibernateRepository<>), typeof(NHibernateRepository<>));
            container.AddComponent("repositoryWithTypedId",
                typeof(IRepositoryWithTypedId<,>), typeof(RepositoryWithTypedId<,>));
            container.AddComponent("nhibernateRepositoryWithTypedId",
                typeof(INHibernateRepositoryWithTypedId<,>), typeof(NHibernateRepositoryWithTypedId<,>));

            //Custom Repositories
            container.Register(
                AllTypes.Pick()
                .FromAssemblyNamed("SimpleStore.Data")
                .WithService.FirstNonGenericCoreInterface("SimpleStore.Core"));

            //Validator
            container.AddComponent("validator",
                typeof(IValidator), typeof(Validator));

            ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
        }
        /// <summary>
        /// Instantiate the container and add all Controllers that derive from
        /// WindsorController to the container.  Also associate the Controller
        /// with the WindsorContainer ControllerFactory.
        /// </summary>
        protected virtual void InitializeServiceLocator()
        {
            var container = new WindsorContainer();

            // Initialize MVC application
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
            container.RegisterControllers(typeof(HomeController).Assembly);
            ComponentRegistrar.AddComponentsTo(container);

            // Initialize WebApi
            container.Register(AllTypes.FromAssembly(typeof(HomeController).Assembly)
                                        .BasedOn<ApiController>()
                                        .If(r => r.Name.EndsWith("Controller"))
                                        .LifestyleTransient());

            GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator),
                new WindsorCompositionRoot(container));

            GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(container);

            // Setup service locator
            var windsorServiceLocator = new WindsorServiceLocator(container);
            DomainEvents.ServiceLocator = windsorServiceLocator;
            ServiceLocator.SetLocatorProvider(() => windsorServiceLocator);
        }
Beispiel #18
0
        protected virtual void InitializeWindsor()
        {
            if (_container == null)
            {
                _container = new WindsorContainer(
                 new XmlInterpreter(new ConfigResource("castle")));

                ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(Container));
                _container.RegisterControllers(typeof(HomeController).Assembly);
            }
        }