示例#1
0
        public void Execute()
        {
            //create container and locator
            var container = new WindsorContainer();
            container.Register(Component.For<IWindsorContainer>().Instance(container).LifestyleSingleton());
            var serviceLocator = new WindsorServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            //register areas, filters, routes, boundles
            AreaRegistration.RegisterAllAreas();

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

            //register data container and repositories
            //DataAccessConfigHelper.ConfigureContainer<PerHttpContextUnitOfWorkScope, DataContainer>(container,
            //   () =>
            //   {
            //       var ctx = new DataContainer();
            //       return ctx;
            //   });

            //
            //register api controllers
            container.Register(Classes.FromThisAssembly()
                                   .BasedOn<ApiController>()
                                   .WithService.Self()
                                   .LifestyleTransient());
            //register controllers
            container.Register(Classes.FromThisAssembly()
                                   .BasedOn<Controller>()
                                   .WithService.Self()
                                   .LifestyleTransient());

            //run DataBootstrapper
            //(new DataBootstrapper()).Execute();

            ////run ApplicationBootstrapper
            //(new ApplicationBootstrapper()).Execute();

            ////run facadeBootstrapper
            //(new FacadeBootstrapper()).Execute();

            //set default resolver
            System.Web.Mvc.IDependencyResolver resolver = new MITD.Core.IocDependencyResolver();
            DependencyResolver.SetResolver(resolver);
            GlobalConfiguration.Configuration.DependencyResolver = resolver.ToServiceResolver();

            //}
            //catch (Exception EX)
            //{

            //    throw EX;
            //}
        }
示例#2
0
        public void Execute()
        {
            #region create WindsorContainer and Locator

            var container = new WindsorContainer();
            container.Kernel.ReleasePolicy = new NoTrackingReleasePolicy();

            container.Register(Component.For<IWindsorContainer>().Instance(container).LifestyleSingleton());
            var serviceLocator = new WindsorServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            #endregion

            #region register areas, filters, routes, boundles
            AreaRegistration.RegisterAllAreas();

            container.Register(
              Component.For<IApplicationLogger>()
              .ImplementedBy<ApplicationLogger>().
                  LifestyleSingleton());

            container.Register(
                Component.For<IFuelApplicationExceptionAdapter>()
                .ImplementedBy<FuelApplicationExceptionAdapter>().
                    LifestyleSingleton());

            container.Register(
                        Component.For<GlobalExceptionHandlingAttribute>()
                        .ImplementedBy<GlobalExceptionHandlingAttribute>().
                            LifestyleSingleton());

            #endregion

            #region register data container and repositories
            DataAccessConfigHelper.ConfigureContainer<PerHttpContextUnitOfWorkScope, DataContainer>(container,
               () =>
               {
                   var connectionString = ConfigurationManager.ConnectionStrings["DataContainer"];
                   var ctx = new DataContainer(connectionString.ConnectionString);
                   return ctx;
               });

            #endregion

            #region register MVC

            //register api controllers
            container.Register(Classes.FromThisAssembly()
                                   .BasedOn<ApiController>()
                                   .WithService.Self()
                                   .LifestyleTransient());
            //register controllers
            container.Register(Classes.FromThisAssembly()
                                   .BasedOn<Controller>()
                                   .WithService.Self()
                                   .LifestyleTransient());
            #endregion

            #region register IdGenerator

            //container.Register(Component.For<IOrderFactory>().ImplementedBy<OrderFactory>().LifestyleSingleton());

            #endregion

            var fromAssemblyDescriptor = Classes.FromAssemblyInDirectory(new AssemblyFilter("bin", "*Fuel*"));

            // factory
            container.Register(fromAssemblyDescriptor
                       .BasedOn(typeof(IFactory))
                       .WithService.FromInterface()
                       .LifestyleTransient());

            container.Register(fromAssemblyDescriptor
                       .BasedOn(typeof(ICodeGenerator))
                       .WithService.FromInterface()
                       .LifestyleTransient());

            container.Register(fromAssemblyDescriptor
                       .BasedOn(typeof(IEntityConfigurator<>))
                       .WithService.FromInterface()
                       .LifestyleTransient());

            // eventNotifier
            container.Register(fromAssemblyDescriptor
                       .BasedOn(typeof(IEventNotifier))
                       .WithService.FromInterface()
                       .LifestyleTransient());

            #region register AntiCorruption
            //adapters
            container.Register(fromAssemblyDescriptor
                                   .BasedOn(typeof(IAntiCorruptionAdapter))
                                   .WithService.FromInterface()
                                   .LifestyleTransient());

            //ServiceWrapper
            container.Register(fromAssemblyDescriptor
                                  .BasedOn(typeof(IAntiCorruptionServiceWrapper))
                                   .WithServiceAllInterfaces()
                // .WithService.FromInterface()
                                   .LifestyleTransient());

            //mappers
            container.Register(fromAssemblyDescriptor
                                   .BasedOn(typeof(IMapper))
                                      .WithService.FromInterface()
                                   .LifestyleTransient());

            #endregion

            #region register Application

            container.Register(fromAssemblyDescriptor
                                 .BasedOn<IApplicationService>()
                                 .WithServiceFromInterface()
                                 .LifestyleTransient());

            #endregion

            #region register Facade

            container.Register(

                fromAssemblyDescriptor
                    .BasedOn(typeof(IFacadeService))
                    .WithServiceFromInterface().LifestyleTransient());

            container.Register(
                Component.For<IFacadeService>().
                Interceptors(InterceptorReference.ForType<SecurityInterception>())
               .Anywhere, Component.For<SecurityInterception>());
            container.Register(
                Component.For<ISecurityServiceChecker>()
                .ImplementedBy<SecurityServiceChecker>()
                .LifestyleTransient());

            #endregion

            // Log
            container.Register(
               Component.For<ILoggerService>().ImplementedBy<DbLoggerService>().Named("DB").LifeStyle.Transient,
               Component.For<ILoggerService>().ImplementedBy<FileLoggerService>().Named("File").LifeStyle.Transient

               );

            //externalHostAddressHelper
            container.Register(Component.For<ExternalHostAddressHelper>()
                                   .ImplementedBy<ExternalHostAddressHelper>()
                                   .LifestyleTransient());

            //domainServices
            container.Register(
            fromAssemblyDescriptor

                                   .BasedOn(typeof(IDomainService<>))
                                   .WithServiceAllInterfaces()
                                   .LifestyleTransient());
            container.Register(
            fromAssemblyDescriptor

                                   .BasedOn(typeof(IDomainService))
                                   .WithServiceAllInterfaces()
                                   .LifestyleTransient());

            var assemblyDescriptor = Classes.FromAssemblyInDirectory(new AssemblyFilter("bin", "*AutomaticVoucher*"));
            container.Register(assemblyDescriptor
                              .BasedOn<IAutomaticVoucher>()
                              .WithServiceFromInterface()
                              .LifestyleTransient());

            #region register Repositories
            container.Register(Component.For(typeof(MITD.Domain.Repository.IRepository<>))
                                   .ImplementedBy(typeof(EFRepository<>))
                                   .LifestyleTransient());

            container.Register(
              fromAssemblyDescriptor
                                   .BasedOn<MITD.Domain.Repository.IRepository>()
                                   .WithServiceFromInterface()
                                   .LifestyleTransient());

            #endregion

            #region excute Bootstrapper
            foreach (var bootstrapper in this.GetBootstrappers())
            {
                bootstrapper.Execute();
            }
            #endregion

            #region set default resolver
            System.Web.Mvc.IDependencyResolver resolver = new MITD.Core.IocDependencyResolver();
            DependencyResolver.SetResolver(resolver);
            GlobalConfiguration.Configuration.DependencyResolver = resolver.ToServiceResolver();
            #endregion

            container.Register(Component.For<IEventPublisher>().ImplementedBy<EventPublisher>().LifeStyle.Transient);

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);

            //Buffer the Unit of Measure and Currencies data into the Application.
            //container.Resolve<IUnitOfMeasuresAndCurrenciesFacadeService>().Reload();
            UnitOfMeasuresAndCurrenciesRegsitrar.ReloadData();
        }