示例#1
0
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //data layer

            builder.Register(x => new EfDataProviderManager(x.Resolve<DataSettings>())).As<BaseDataProviderManager>().InstancePerDependency();

            builder.RegisterType(SqlServerDataProvider).As<IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register<IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerHttpRequest();
            }
            else
            {
                builder.Register<IDbContext>(c => new NopObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerHttpRequest();
            }

            builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).InstancePerHttpRequest();

            ////builder.RegisterType<ContentService>().As<IContentService>().InstancePerHttpRequest();
            ////builder.RegisterType<NodeService>().As<INodeService>().InstancePerHttpRequest();
        }
示例#2
0
        /// <summary>
        ///     Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, ServerConfig config)
        {
            var          dataSettingsManager  = new DataSettingsManager();
            DataSettings dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.CacheSettings).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>()))
            .As <BaseDataProviderManager>()
            .InstancePerDependency();

            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider())
            .As <IDataProvider>()
            .InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var           efDataProviderManager = new EfDataProviderManager(dataSettingsManager.CacheSettings);
                IDataProvider dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();
                builder.Register <IDbContext>(c => new AppContext(dataProviderSettings.DataConnectionString))
                .InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(
                    c => new AppContext(dataSettingsManager.CacheSettings.DataConnectionString))
                .InstancePerLifetimeScope();
            }

            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            /*********************************************
            *   CACHE MANAGERS
            *********************************************/
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("app_cache_static").SingleInstance();

            /*************************************************************
            *   REGISTER TYPE SERVCIES
            *************************************************************/
            builder.RegisterType <ChatLieuService>().As <IChatLieuService>().SingleInstance();
            builder.RegisterType <ChiTietHDBService>().As <IChiTietHDBService>().SingleInstance();
            builder.RegisterType <ChiTietHDNService>().As <IChiTietHDNService>().SingleInstance();
            builder.RegisterType <CongViecService>().As <ICongViecService>().SingleInstance();
            builder.RegisterType <DoiTuongService>().As <IDoiTuongService>().SingleInstance();
            builder.RegisterType <HoaDonBanService>().As <IHoaDonBanService>().SingleInstance();
            builder.RegisterType <HoaDonNhapService>().As <IHoaDonNhapService>().SingleInstance();
            builder.RegisterType <KhachHangService>().As <IKhachHangService>().SingleInstance();
            builder.RegisterType <KichCoService>().As <IKichCoService>().SingleInstance();
            builder.RegisterType <MauService>().As <IMauService>().SingleInstance();
            builder.RegisterType <MuaService>().As <IMuaService>().SingleInstance();
            builder.RegisterType <NhaCungCapService>().As <INhaCungCapService>().SingleInstance();
            builder.RegisterType <NhanVienService>().As <INhanVienService>().SingleInstance();
            builder.RegisterType <NuocSanXuatService>().As <INuocSanXuatService>().SingleInstance();
            builder.RegisterType <SanPhamService>().As <ISanPhamService>().SingleInstance();
            builder.RegisterType <TheLoaiService>().As <ITheLoaiService>().SingleInstance();
        }
        public static void Register(IAppBuilder app, HttpConfiguration config)
        {
            ContainerBuilder builder = new ContainerBuilder();



            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings(GlobalAppSettings.DataProvider, GlobalAppSettings.MySqlConnection);

            builder.Register(c => dataProviderSettings).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();


            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataProviderSettings);
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.Register <IDapperRepository>(c => new MysqlDapperRepository(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();

            //services
            var Services  = Assembly.Load("Community.Service");
            var IServices = Assembly.Load("Community.IService");

            builder.RegisterAssemblyTypes(IServices, Services)
            .Where(t => t.Name.EndsWith("Service"))
            .AsImplementedInterfaces();



            // Register your Web API controllers.
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();



            var container = builder.Build();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            // Register the Autofac middleware FIRST, then the Autofac Web API middleware,
            // and finally the standard Web API middleware.
            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);
        }
示例#4
0
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, IndividualsServicesConfig config)
        {
            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings(connectionStringName: config.SqlConnection);

            builder.Register(c => dataProviderSettings).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();

            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataProviderSettings);
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new IndividualsServicesObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new IndividualsServicesObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }

            //repositories
            builder.RegisterGeneric(typeof(EfRepository <,>)).As(typeof(IRepository <,>)).InstancePerLifetimeScope();

            //cache manager
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().SingleInstance();


            //services
            builder.RegisterType <LaborerService>().As <ILaborerService>().InstancePerLifetimeScope();
            builder.RegisterType <ServiceLogService>().As <IServiceLogService>().InstancePerLifetimeScope();

            builder.RegisterType <NitaqatService>().As <INitaqatService>().InstancePerLifetimeScope();
            builder.RegisterType <EstablishmentService>().As <IEstablishmentService>().InstancePerLifetimeScope();
            builder.RegisterType <RunawayService>().As <IRunawayService>().InstancePerLifetimeScope();
            builder.RegisterType <SponsorTransferService>().As <ISponsorTransferService>().InstancePerLifetimeScope();

            var oracleRepo = new OracleRepository(config.OracleConnection.ConnectionString, config.OracleConnection.Schema);

            builder.Register <IOracleRepository>(ora => oracleRepo).InstancePerLifetimeScope();


            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();
            //register all settings
            builder.RegisterSource(new SettingsSource());
        }
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, VConfig config)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();

            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();
            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new VObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new VObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            //repository
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            #region services
            builder.RegisterType <PostService>().As <IPostService>().InstancePerLifetimeScope();
            #endregion
        }
示例#6
0
        public void Register(ContainerBuilder containerBuilder, ITypeFinder typeFinder, AppConfig appConfig)
        {
            // Http Context
            containerBuilder.Register(c =>
                                      HttpContext.Current != null ?
                                      (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
                                      (null))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();

            // Controllers
            containerBuilder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            // DAL
            DataSettingsManager dataSettingsManager = new DataSettingsManager();
            var dataSettings = dataSettingsManager.LoadSettings();

            containerBuilder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            containerBuilder.Register(c => new EfDataProviderManager(c.Resolve <DataSettings>()))
            .As <BaseDataProviderManager>().InstancePerDependency();

            containerBuilder.Register(c => c.Resolve <BaseDataProviderManager>().LoadDataProvider())
            .As <IDataProvider>().InstancePerDependency();

            if (dataSettings != null && dataSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettings);
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                containerBuilder.Register <IDbContext>(c => new AppObjectContext(dataSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                containerBuilder.Register <IDbContext>(c => new AppObjectContext(dataSettingsManager.LoadSettings().DataConnectionString))
                .InstancePerLifetimeScope();
            }

            containerBuilder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            //Service
            containerBuilder.RegisterType <FormAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            containerBuilder.RegisterType <StudentService>().As <IStudentService>().InstancePerLifetimeScope();
            containerBuilder.RegisterType <StudentRegistrationService>().As <IStudentRegistrationService>().InstancePerLifetimeScope();
            containerBuilder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();

            //Route Publisher
            containerBuilder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
        }
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, MSTConfig config)
        {
            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();

            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new MstDbContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new MstDbContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }



            //repositories
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
            //services
            builder.RegisterType <GenderService>().As <IGenderService>().InstancePerLifetimeScope();
            builder.RegisterType <CountryService>().As <ICountryService>().InstancePerLifetimeScope();
            builder.RegisterType <OrganizationService>().As <IOrganizationService>().InstancePerLifetimeScope();
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <EmailService>().As <IEmailService>().InstancePerLifetimeScope();
            builder.RegisterType <PatientService>().As <IPatientService>().InstancePerLifetimeScope();
            builder.RegisterType <PatientVisitService>().As <IPatientVisitService>().InstancePerLifetimeScope();
            builder.RegisterType <OrganizationPharmacyService>().As <IOrganizationPharmacyService>().InstancePerLifetimeScope();
            builder.RegisterType <CheifComplainService>().As <ICheifComplainService>().InstancePerLifetimeScope();
            builder.RegisterType <AzureStorage>().As <IStorage>().InstancePerLifetimeScope();
            //installation service

            builder.RegisterType <CodeFirstInstallationService>().As <IInstallationService>().InstancePerLifetimeScope();
        }
示例#8
0
        public void Configuration(IAppBuilder app)
        {
            var engine = new TenantEngine(new TenantConfiguration
            {
                IdentificationStrategy = RequestIdentificationStrategies.FromHostname,
                TenantResolver         = new SampleResolver()
            });

            var builder = new ContainerBuilder();

            builder.Register(x => new EfDataProviderManager()).As <BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            var efDataProviderManager = new EfDataProviderManager();
            var dataProvider          = efDataProviderManager.LoadDataProvider();

            builder.Register <IDbContext>(c => new DomainObjectContext()).InstancePerHttpRequest();
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerHttpRequest();

            //Core
            builder.RegisterType <TenantService>().As <ITenantService>().InstancePerHttpRequest();
            builder.RegisterType <ThemeService>().As <IThemeService>().InstancePerHttpRequest();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerHttpRequest();
            builder.RegisterType <StateService>().As <IStateService>().InstancePerLifetimeScope();

            //Web and Api Controllers auto config
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            //Sample Services
            builder.RegisterType <ContactService>().As <IContactService>().InstancePerHttpRequest();
            builder.RegisterType <EventService>().As <IEventService>().InstancePerHttpRequest();
            builder.RegisterType <MediaService>().As <IMediaService>().InstancePerHttpRequest();
            builder.RegisterType <MenuService>().As <IMenuService>().InstancePerHttpRequest();
            builder.RegisterType <NewsletterService>().As <INewsletterService>().InstancePerHttpRequest();
            builder.RegisterType <PageService>().As <IPageService>().InstancePerHttpRequest();
            builder.RegisterType <PostService>().As <IPostService>().InstancePerHttpRequest();

            var container          = builder.Build();
            var dependencyResolver = new AutofacWebApiDependencyResolver(container);

            GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver;
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            app.UseAutofacMiddleware(container);
            app.UseMultiTenancy(engine);
        }
示例#9
0
        public void Register(ContainerBuilder builder)
        {
            builder.Register(x => new EfDataProviderManager()).As <BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            var efDataProviderManager = new EfDataProviderManager();
            var dataProvider          = efDataProviderManager.LoadDataProvider();

            dataProvider.InitConnectionFactory();

            builder.Register <IDbContext>(c => new DbgoObjectContext("Dbgo")).InstancePerLifetimeScope();

            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();

            //builder.RegisterType<ScheduleTaskService>().As<IScheduleTaskService>().InstancePerLifetimeScope();
        }
示例#10
0
        public void Configuration(IAppBuilder app)
        {
            var engine = new TenantEngine(new TenantConfiguration
            {
                IdentificationStrategy = RequestIdentificationStrategies.FromHostname,
                TenantResolver = new SampleResolver()
            });

            var builder = new ContainerBuilder();
            builder.Register(x => new EfDataProviderManager()).As<BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve<BaseDataProviderManager>().LoadDataProvider()).As<IDataProvider>().InstancePerDependency();

            var efDataProviderManager = new EfDataProviderManager();
            var dataProvider = efDataProviderManager.LoadDataProvider();

            builder.Register<IDbContext>(c => new DomainObjectContext()).InstancePerHttpRequest();
            builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).InstancePerHttpRequest();

            //Core
            builder.RegisterType<TenantService>().As<ITenantService>().InstancePerHttpRequest();
            builder.RegisterType<ThemeService>().As<IThemeService>().InstancePerHttpRequest();
            builder.RegisterType<SettingService>().As<ISettingService>().InstancePerHttpRequest();
            builder.RegisterType<StateService>().As<IStateService>().InstancePerLifetimeScope();

            //Web and Api Controllers auto config
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            //Sample Services
            builder.RegisterType<ContactService>().As<IContactService>().InstancePerHttpRequest();
            builder.RegisterType<EventService>().As<IEventService>().InstancePerHttpRequest();
            builder.RegisterType<MediaService>().As<IMediaService>().InstancePerHttpRequest();
            builder.RegisterType<MenuService>().As<IMenuService>().InstancePerHttpRequest();
            builder.RegisterType<NewsletterService>().As<INewsletterService>().InstancePerHttpRequest();
            builder.RegisterType<PageService>().As<IPageService>().InstancePerHttpRequest();
            builder.RegisterType<PostService>().As<IPostService>().InstancePerHttpRequest();
            
            var container = builder.Build();
            var dependencyResolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver;
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            app.UseAutofacMiddleware(container);
            app.UseMultiTenancy(engine);
        }
示例#11
0
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, WonderLabsConfig config)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();

            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();

            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new WonderLabsObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new WonderLabsObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();


            builder.RegisterType <SettingService>().As <ISettingService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope();

            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
        }
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            var dataProviderManager = new EfDataProviderManager();
            var dataSettings = dataProviderManager.DataSettings;
            Guard.MustFollow(() => dataSettings.NotNull() && dataSettings.IsValid(),
                () => { throw new Saturn72Exception("Failed to read DataSettings."); });

            var dataProvider = dataProviderManager.DataProvider;
            Guard.NotNull(dataProvider, "no database provider was found");
            builder.RegisterInstance(dataProvider).As<IDatabaseProvider>().SingleInstance();

            var nameOrConnectionString = dataSettings.DataConnectionString.HasValue()
                ? dataSettings.DataConnectionString
                : dataSettings.DatabaseName;

            builder.Register<IDbContext>(c => new Saturn72ObjectContext(nameOrConnectionString))
                .InstancePerLifetimeScope();

            builder.RegisterGeneric(typeof (EfRepository<>)).As(typeof (IRepository<>)).InstancePerLifetimeScope();
        }
示例#13
0
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //Framework.UI
            builder.RegisterType <PageBulider>().As <IPageBulider>().InstancePerLifetimeScope();

            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            // Core
            builder.Register(x => new SettingsManager().LoadSettings()).As <Settings>();
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().SingleInstance();

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();
            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerRequest();
            }
            else
            {
                builder.Register <IDbContext>(c => new NopObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerRequest();
            }

            // Repository
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            // Services
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <DBLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizationService>().As <ILocalizationService>().InstancePerLifetimeScope();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="typeFinder"></param>
        /// <param name="config"></param>
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();
                builder.Register <IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new NopObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }
        }
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            // EntityFramework  Repository Context & Repositories
            var dbset = DbSetting.FindOrCreate("LCL");
            var efDataProviderManager = new EfDataProviderManager(dbset);
            var dataProvider          = efDataProviderManager.LoadDataProvider();

            dataProvider.InitConnectionFactory();
            builder.Register(c => dbset).As <DbSetting>();
            builder.Register <LclDbContext>(c => new EFTestContext(dbset.ConnectionString)).As(typeof(IRepositoryContext)).Named <IRepositoryContext>(dbset.Name).InstancePerLifetimeScope();
            builder.Register <IRepositoryContext>(c => new EFTestContext(dbset.ConnectionString)).Named <IRepositoryContext>(dbset.Name).InstancePerLifetimeScope();

            builder.RegisterType <CategorizationRepository>().As <ICategorizationRepository>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryRepository>().As <ICategoryRepository>().InstancePerLifetimeScope();
            builder.RegisterType <ProductRepository>().As <IProductRepository>().InstancePerLifetimeScope();
            builder.RegisterType <SalesOrderRepository>().As <ISalesOrderRepository>().InstancePerLifetimeScope();
            builder.RegisterType <ShoppingCartItemRepository>().As <IShoppingCartItemRepository>().InstancePerLifetimeScope();
            builder.RegisterType <ShoppingCartRepository>().As <IShoppingCartRepository>().InstancePerLifetimeScope();
            builder.RegisterType <RoleRepository>().As <IRoleRepository>().InstancePerLifetimeScope();
            builder.RegisterType <UserRoleRepository>().As <IUserRoleRepository>().InstancePerLifetimeScope();
            builder.RegisterType <UserRepository>().As <IUserRepository>().InstancePerLifetimeScope();

            // Event Handlers
            builder.RegisterType <SendEmailHandler>().As <IEventHandler <OrderDispatchedEvent> >().InstancePerLifetimeScope();
            builder.RegisterType <SendEmailHandler>().As <IEventHandler <OrderConfirmedEvent> >().InstancePerLifetimeScope();

            // Domain Event Handlers
            builder.RegisterType <GetUserOrdersEvent>().As <IDomainEventHandler <GetUserOrdersEvent> >().InstancePerLifetimeScope();
            builder.RegisterType <OrderDispatchedEventHandler>().As <IDomainEventHandler <OrderDispatchedEvent> >().InstancePerLifetimeScope();
            builder.RegisterType <OrderConfirmedEventHandler>().As <IDomainEventHandler <OrderConfirmedEvent> >().InstancePerLifetimeScope();

            // Event Aggregator

            // Server
            builder.RegisterType <OrderService>().As <IOrderService>().InstancePerLifetimeScope();


            System.Diagnostics.Debug.WriteLine(Order + " init plugin LCL.Plugin.EasyUI.UCenter");
        }
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());
            //data access
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            //todo:暂时把连接字符串写死,测试时使用
            //dataProviderSettings.DataConnectionString = @"Data Source=(localdb)\ProjectsV12;Initial Catalog=FzrainFramework;attachdbfilename=E:\MyFramework\Fzrain.Framework\Fzrain.Web\App_Data\FzrainFramework.mdf;Integrated Security=True;Persist Security Info=False;";
            //dataProviderSettings.DataProvider = "sqlserver";
            builder.Register(c => dataProviderSettings).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();


            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataProviderSettings);
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new FzrainContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new FzrainContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }
            //repository
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();


            //service
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <LolService>().As <ILolService>().InstancePerLifetimeScope();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();
        }
示例#17
0
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, CH3Config config)
        {
            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();

            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new CH3ObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new CH3ObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }



            //repositories
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();

            //installation service
            if (!DataSettingsHelper.DatabaseIsInstalled())
            {
                builder.RegisterType <CodeFirstInstallationService>().As <IInstallationService>().InstancePerLifetimeScope();
            }
        }
示例#18
0
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();
                builder.Register <IDbContext>(c => new AssesmentDbContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new AssesmentDbContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            EventFlowOptions.New
            .UseAutofacContainerBuilder(builder)
            //.PublishToRabbitMq(RabbitMqConfiguration.With(new Uri("amqp://*****:*****@192.168.99.100/")))
            .ConfigureMsSql(MsSqlConfiguration.New.SetConnectionString(DataSettings.Current.DataConnectionString))
            .UseMssqlEventStore()
            .ConfigureAggregates()
            .ConfigureReadModels();


            builder.RegisterType <AssesmentModuleService>().As <IAssesmentModuleService>().InstancePerLifetimeScope();

            builder.Register <IUserEvent>(c => new UserEvent {
                User = "******"
            });
        }
示例#19
0
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, GameConfig config)
        {
            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();

            //user agent helper
            builder.RegisterType <UserAgentHelper>().As <IUserAgentHelper>().InstancePerLifetimeScope();

            //data layer
            builder.RegisterType <GameCoreConventionSetBuilder>().As <ICoreConventionSetBuilder>().SingleInstance();
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();
            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();

                builder.Register <IDbContext>(c => new GameObjectContext(dataProvider)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => {
                    dataProviderSettings = dataSettingsManager.LoadSettings();
                    if (dataProviderSettings != null && dataProviderSettings.IsValid())
                    {
                        var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                        var dataProvider          = efDataProviderManager.LoadDataProvider();
                        return(new GameObjectContext(dataProvider));
                    }
                    else
                    {
                        return(new GameObjectContext(null));
                    }
                }).InstancePerLifetimeScope();
            }


            //repositories
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            //cache manager
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().InstancePerLifetimeScope();

            //static cache manager
            if (config.RedisCachingEnabled)
            {
                builder.RegisterType <RedisConnectionWrapper>().As <IRedisConnectionWrapper>().SingleInstance();
                builder.RegisterType <RedisCacheManager>().As <IStaticCacheManager>().InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>().As <IStaticCacheManager>().SingleInstance();
            }

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();

            //services
            //builder.RegisterType<BackInStockSubscriptionService>().As<IBackInStockSubscriptionService>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            //builder.RegisterType<FulltextService>().As<IFulltextService>().InstancePerLifetimeScope();
            //builder.RegisterType<MaintenanceService>().As<IMaintenanceService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeFormatter>().As <ICustomerAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeParser>().As <ICustomerAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeService>().As <ICustomerAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRegistrationService>().As <ICustomerRegistrationService>().InstancePerLifetimeScope();
            //builder.RegisterType<CustomerReportService>().As<ICustomerReportService>().InstancePerLifetimeScope();
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <AclService>().As <IAclService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizationService>().As <ILocalizationService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();
            //builder.RegisterType<DownloadService>().As<IDownloadService>().InstancePerLifetimeScope();
            //builder.RegisterType<MessageTemplateService>().As<IMessageTemplateService>().InstancePerLifetimeScope();
            //builder.RegisterType<QueuedEmailService>().As<IQueuedEmailService>().InstancePerLifetimeScope();
            //builder.RegisterType<NewsLetterSubscriptionService>().As<INewsLetterSubscriptionService>().InstancePerLifetimeScope();
            //builder.RegisterType<CampaignService>().As<ICampaignService>().InstancePerLifetimeScope();
            //builder.RegisterType<EmailAccountService>().As<IEmailAccountService>().InstancePerLifetimeScope();
            //builder.RegisterType<EmailSender>().As<IEmailSender>().InstancePerLifetimeScope();
            //builder.RegisterType<ReturnRequestService>().As<IReturnRequestService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CookieAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UrlRecordService>().As <IUrlRecordService>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerActivityService>().As <ICustomerActivityService>().InstancePerLifetimeScope();
            builder.RegisterType <DateTimeHelper>().As <IDateTimeHelper>().InstancePerLifetimeScope();
            builder.RegisterType <SitemapGenerator>().As <ISitemapGenerator>().InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();
            //builder.RegisterType<ExportManager>().As<IExportManager>().InstancePerLifetimeScope();
            //builder.RegisterType<ImportManager>().As<IImportManager>().InstancePerLifetimeScope();
            //builder.RegisterType<PdfService>().As<IPdfService>().InstancePerLifetimeScope();
            //builder.RegisterType<UploadService>().As<IUploadService>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeProvider>().As <IThemeProvider>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeContext>().As <IThemeContext>().InstancePerLifetimeScope();
            builder.RegisterType <ExternalAuthenticationService>().As <IExternalAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();
            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope();
            builder.RegisterType <ActionContextAccessor>().As <IActionContextAccessor>().InstancePerLifetimeScope();
            builder.RegisterType <MatchService>().As <IMatchService>().InstancePerLifetimeScope();
            builder.RegisterType <EcbExchangeRateProvider>().As <IExchangeRateProvider>().InstancePerLifetimeScope();
            builder.RegisterType <CurrencyService>().As <ICurrencyService>().InstancePerLifetimeScope();
            builder.RegisterType <OrderService>().As <IOrderService>().InstancePerLifetimeScope();
            builder.RegisterType <PaymentService>().As <IPaymentService>().InstancePerLifetimeScope();
            builder.RegisterType <PriceFormatter>().As <IPriceFormatter>().InstancePerLifetimeScope();

            //register all settings
            builder.RegisterSource(new SettingsSource());

            //installation service
            if (!DataSettingsHelper.DatabaseIsInstalled())
            {
                if (config.UseFastInstallationService)
                {
                    builder.RegisterType <SqlFileInstallationService>().As <IInstallationService>().InstancePerLifetimeScope();
                }
                else
                {
                    builder.RegisterType <CodeFirstInstallationService>().As <IInstallationService>().InstancePerLifetimeScope();
                }
            }

            //event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
        }
示例#20
0
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            //HTTP上下文注册
            //builder.Register(c =>
            //    //register FakeHttpContext when HttpContext is not available
            //    HttpContext.Current != null ?
            //    (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
            //    (new FakeHttpContext("~/") as HttpContextBase))
            //    .As<HttpContextBase>()
            //    .InstancePerLifetimeScope();
            //builder.Register(c => (new HttpContextWrapper(HttpContext.Current) as HttpContextBase))
            //    .As<HttpContextBase>()
            //    .InstancePerLifetimeScope();
            builder.Register(c => (new HttpContextWrapper(HttpContext.Current) as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();
            //注册,MVC的controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());
            //注册数据层,如dbcontext,manager,repository,供持久化层的操作;
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();
            //注册缓存管理的相关类
            //if (config.RedisCachingEnabled)
            //{
            //    builder.RegisterType<RedisConnectionWrapper>().As<IRedisConnectionWrapper>().SingleInstance();
            //    builder.RegisterType<RedisCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_static").InstancePerLifetimeScope();
            //}
            //else
            //{
            //在IoC容器中把MemoryCacheManager注册为ICacheManager,并且命名为nop_cache_static。
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_static").SingleInstance();
            //}

            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();
            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new FrameworkObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new FrameworkObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }
            //注册插件plugins
            builder.RegisterType <PluginFinder>().As <IPluginFinder>().InstancePerLifetimeScope();
            //注册helper帮助类
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();
            builder.RegisterType <LoggerService>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
            //use static cache (between HTTP requests)
            builder.RegisterType <UrlRecordService>().As <IUrlRecordService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();



            //Register event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
            builder.RegisterType <EmailSender>().As <IEmailSender>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailService>().As <IQueuedEmailService>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountService>().As <IEmailAccountService>().InstancePerLifetimeScope();
            builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetService>().As <IWidgetService>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeProvider>().As <IThemeProvider>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeContext>().As <IThemeContext>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();         //常规属性
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();                         //用户
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();                              //上下文对象
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();                     //权限
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();        //认证
            builder.RegisterType <CustomerRegistrationService>().As <ICustomerRegistrationService>().InstancePerLifetimeScope(); //验证登录注册
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();                     //加密服务
            builder.RegisterType <CustomerActivityService>().As <ICustomerActivityService>().InstancePerLifetimeScope();         //用户日志
            builder.RegisterType <NewsService>().As <INewsService>().InstancePerLifetimeScope();                                 //新闻管理
            builder.RegisterType <ContactMessageService>().As <IContactMessageService>().InstancePerLifetimeScope();             //联系管理

            builder.RegisterGeneric(typeof(BaseService <>)).As(typeof(IBaseService <>)).InstancePerLifetimeScope();              //Service基类管理
            builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerLifetimeScope();                         //商品属性管理
            builder.RegisterType <ProductService>().As <IProductService>().InstancePerLifetimeScope();                           //商品管理

            builder.RegisterType <TermService>().As <ITermService>().InstancePerLifetimeScope();                                 //商品管理
            builder.RegisterType <ResourcesService>().As <IResourcesService>().InstancePerLifetimeScope();                       //资源文件管理
            builder.RegisterType <OpenAuthenticationService>().As <IOpenAuthenticationService>().InstancePerLifetimeScope();     //开放接口授权服务
            builder.RegisterType <ExternalAuthorizer>().As <IExternalAuthorizer>().InstancePerLifetimeScope();                   //外部授权服务
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();                         //语言服务
            builder.RegisterType <LocalizationService>().As <ILocalizationService>().InstancePerLifetimeScope();                 //语言资源服务
        }
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             //register FakeHttpContext when HttpContext is not available
                             HttpContext.Current != null ?
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
                             (new FakeHttpContext("~/") as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();

            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();
            ////user agent helper
            //builder.RegisterType<UserAgentHelper>().As<IUserAgentHelper>().InstancePerLifetimeScope();


            //controllers
            builder.RegisterApiControllers(typeFinder.GetAssemblies().ToArray()); // [TO BE  CHECKED FOR WEB API] //Added by Rahul Kumar on 25/02/2016 to include DI for WebAPI
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();


            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new ACSObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new ACSObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }


            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            ////plugins
            //builder.RegisterType<PluginFinder>().As<IPluginFinder>().InstancePerLifetimeScope();

            //cache manager
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_static").SingleInstance();
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_per_request").InstancePerLifetimeScope();


            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();
            ////store context
            //builder.RegisterType<WebStoreContext>().As<IStoreContext>().InstancePerLifetimeScope();

            ////builder.RegisterType<ContactService>().As<IContactService>().InstancePerLifetimeScope();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();
            builder.RegisterType <NavigationService>().As <INavigationService>().InstancePerLifetimeScope();
            /////builder.RegisterType<FlatService>().As<IFlatService>().InstancePerLifetimeScope();

            builder.RegisterType <UserAuthenticationService>().As <IUserAuthenticationService>().InstancePerLifetimeScope();
            //////builder.RegisterType < ACS.Services.User.UserService>().As<ACS.Services.User.IUserService>().InstancePerLifetimeScope();
            //////builder.RegisterType<ACS.Services.Society.TowerService>().As<ACS.Services.Society.ITowerService>().InstancePerLifetimeScope();
            //////builder.RegisterType<ACS.Services.Society.BlockService>().As<ACS.Services.Society.IBlockService>().InstancePerLifetimeScope();
            //////builder.RegisterType<ACS.Services.NoticeBoard.NoticeBoardService>().As<ACS.Services.NoticeBoard.INoticeBoardService>().InstancePerLifetimeScope();
            //////builder.RegisterType<ACS.Services.NoticeBoard.NoticeBoardVisibilityService>().As<ACS.Services.NoticeBoard.INoticeBoardVisibilityService>().InstancePerLifetimeScope();
            //////builder.RegisterType<ACS.Services.NoticeBoard.NotificationService>().As<ACS.Services.NoticeBoard.INotificationService>().InstancePerLifetimeScope();

            ////services
            //builder.RegisterType<BackInStockSubscriptionService>().As<IBackInStockSubscriptionService>().InstancePerLifetimeScope();
            //builder.RegisterType<CategoryService>().As<ICategoryService>().InstancePerLifetimeScope();
            //builder.RegisterType<CompareProductsService>().As<ICompareProductsService>().InstancePerLifetimeScope();
            //builder.RegisterType<RecentlyViewedProductsService>().As<IRecentlyViewedProductsService>().InstancePerLifetimeScope();
            //builder.RegisterType<ManufacturerService>().As<IManufacturerService>().InstancePerLifetimeScope();
            //builder.RegisterType<PriceFormatter>().As<IPriceFormatter>().InstancePerLifetimeScope();
            //builder.RegisterType<ProductAttributeFormatter>().As<IProductAttributeFormatter>().InstancePerLifetimeScope();
            //builder.RegisterType<ProductAttributeParser>().As<IProductAttributeParser>().InstancePerLifetimeScope();
            //builder.RegisterType<ProductAttributeService>().As<IProductAttributeService>().InstancePerLifetimeScope();
            //builder.RegisterType<ProductService>().As<IProductService>().InstancePerLifetimeScope();
            //builder.RegisterType<CopyProductService>().As<ICopyProductService>().InstancePerLifetimeScope();
            //builder.RegisterType<SpecificationAttributeService>().As<ISpecificationAttributeService>().InstancePerLifetimeScope();
            //builder.RegisterType<ProductTemplateService>().As<IProductTemplateService>().InstancePerLifetimeScope();
            //builder.RegisterType<CategoryTemplateService>().As<ICategoryTemplateService>().InstancePerLifetimeScope();
            //builder.RegisterType<ManufacturerTemplateService>().As<IManufacturerTemplateService>().InstancePerLifetimeScope();
            ////pass MemoryCacheManager as cacheManager (cache settings between requests)
            //builder.RegisterType<ProductTagService>().As<IProductTagService>()
            //    .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
            //    .InstancePerLifetimeScope();

            //builder.RegisterType<AffiliateService>().As<IAffiliateService>().InstancePerLifetimeScope();
            //builder.RegisterType<VendorService>().As<IVendorService>().InstancePerLifetimeScope();
            //builder.RegisterType<AddressService>().As<IAddressService>().InstancePerLifetimeScope();
            //builder.RegisterType<SearchTermService>().As<ISearchTermService>().InstancePerLifetimeScope();
            // builder.RegisterType<GenericAttributeService>().As<IGenericAttributeService>().InstancePerLifetimeScope();
            //builder.RegisterType<FulltextService>().As<IFulltextService>().InstancePerLifetimeScope();
            //builder.RegisterType<MaintenanceService>().As<IMaintenanceService>().InstancePerLifetimeScope();


            //builder.RegisterType<CustomerAttributeParser>().As<ICustomerAttributeParser>().InstancePerLifetimeScope();
            //builder.RegisterType<CustomerAttributeService>().As<ICustomerAttributeService>().InstancePerLifetimeScope();
            //builder.RegisterType<CustomerService>().As<ICustomerService>().InstancePerLifetimeScope();
            //builder.RegisterType<CustomerRegistrationService>().As<ICustomerRegistrationService>().InstancePerLifetimeScope();
            //builder.RegisterType<CustomerReportService>().As<ICustomerReportService>().InstancePerLifetimeScope();

            ////pass MemoryCacheManager as cacheManager (cache settings between requests)
            //builder.RegisterType<PermissionService>().As<IPermissionService>()
            //    .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
            //    .InstancePerLifetimeScope();
            ////pass MemoryCacheManager as cacheManager (cache settings between requests)
            //builder.RegisterType<AclService>().As<IAclService>()
            //    .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
            //    .InstancePerLifetimeScope();
            ////pass MemoryCacheManager as cacheManager (cache settings between requests)
            //builder.RegisterType<PriceCalculationService>().As<IPriceCalculationService>()
            //    .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
            //    .InstancePerLifetimeScope();

            //builder.RegisterType<GeoLookupService>().As<IGeoLookupService>().InstancePerLifetimeScope();

            //builder.RegisterType<CountryService>().As<ICountryService>().InstancePerLifetimeScope();
            //builder.RegisterType<StateService>().As<IStateService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Master.DepartmentService>().As <ACS.Services.Master.IDepartmentService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Master.CommonListService>().As <ACS.Services.Master.ICommonListService>().InstancePerLifetimeScope();



            builder.RegisterType <ACS.Services.User.UserService>().As <ACS.Services.User.IUserService>().InstancePerLifetimeScope();


            builder.RegisterType <ACS.Services.Contact.ContactService>().As <ACS.Services.Contact.IContactService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Master.DivisionService>().As <ACS.Services.Master.IDivisionService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Common.CommonDropDown>().As <ACS.Services.Common.ICommonDropDown>().InstancePerLifetimeScope();


            builder.RegisterType <ACS.Services.Master.Exeutive>().As <ACS.Services.Master.IExecutive>().InstancePerLifetimeScope();
            //// service add by anjali
            //// created by 05/13/2016 for ProductTypeService
            builder.RegisterType <ACS.Services.Master.ProductTypeService>().As <ACS.Services.Master.IProductType>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Master.PageAccessService>().As <ACS.Services.Master.IPageAccessService>().InstancePerLifetimeScope();
            // added by saddam 17/05/2016
            builder.RegisterType <ACS.Services.Master.AuthorService>().As <ACS.Services.Master.IAuthorService>().InstancePerLifetimeScope();
            //ended saddam

            //Added By sanjeet 18/05/2016
            builder.RegisterType <ACS.Services.Master.PublishingCompanyService>().As <ACS.Services.Master.IPublishingCompanyService>().InstancePerLifetimeScope();
            //


            // added by saddam 25/05/2016
            builder.RegisterType <ACS.Services.Master.CustomProductService>().As <ACS.Services.Master.ICustomProductService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Product.ProductMasterService>().As <ACS.Services.Product.IProductMasterService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Product.ProductLicenseService>().As <ACS.Services.Product.IProductLicenseService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Product.AddendumServices>().As <ACS.Services.Product.IAddendumServices>().InstancePerLifetimeScope();

            //ended saddam

            // added by saddam 30/05/2016
            builder.RegisterType <ACS.Services.Master.ApplicationSetUpService>().As <ACS.Services.Master.IApplicationSetUpService>().InstancePerLifetimeScope();

            //ended saddam

            // added by saddam 14/06/2016
            builder.RegisterType <ACS.Services.Other_Contract.OtherContractService>().As <ACS.Services.Other_Contract.IOtherContractService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.AuthorContract.AuthorContractService>().As <ACS.Services.AuthorContract.IAuthorContractService>().InstancePerLifetimeScope();
            //ended saddam

            // added by saddam 01/07/2016
            builder.RegisterType <ACS.Services.Master.ISBNService>().As <ACS.Services.Master.IISBNService>().InstancePerLifetimeScope();
            //ended saddam

            // added by saddam 27/07/2016
            builder.RegisterType <ACS.Services.RightsSelling.RightsSelling>().As <ACS.Services.RightsSelling.IRightsSelling>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.PermissionsOutbound.PermissionsOutboundService>().As <ACS.Services.PermissionsOutbound.IPermissionsOutboundService>().InstancePerLifetimeScope();
            //ended saddam

            //Added by Saddam on 02/08/2016
            builder.RegisterType <ACS.Services.PermissionsInbound.PermissionsInboundService>().As <ACS.Services.PermissionsInbound.IPermissionsInboundService>().InstancePerLifetimeScope();
            //ended by Saddam

            //Added by Suranjana 11/07/2016
            builder.RegisterType <ACS.Services.Master.TypeOfRightsService>().As <ACS.Services.Master.ITypeOfRightsService>().InstancePerLifetimeScope();
            //ended Suranjana

            //Added by Ankush
            //12/07/2016
            builder.RegisterType <ACS.Services.Master.SubsidiaryRightsService>().As <ACS.Services.Master.ISubsidiaryRightsService>().InstancePerLifetimeScope();

            //13/07/2016
            builder.RegisterType <ACS.Services.Master.GeographicalService>().As <ACS.Services.Master.IGeographicalService>().InstancePerLifetimeScope();
            //14/07/2016
            builder.RegisterType <ACS.Services.Master.LanguageMasterService>().As <ACS.Services.Master.ILanguageMasterService>().InstancePerLifetimeScope();
            //15/07/2016
            builder.RegisterType <ACS.Services.Master.ImprintService>().As <ACS.Services.Master.IImprintService>().InstancePerLifetimeScope();

            //ended Ankush

            //Added by Suranjana 13/07/2016
            builder.RegisterType <ACS.Services.Master.TerritoryRightsService>().As <ACS.Services.Master.ITerritoryRightsService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Master.ManuscriptDeliveryFormatService>().As <ACS.Services.Master.IManuscriptDeliveryFormatService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Master.SupplyMaterialService>().As <ACS.Services.Master.ISupplyMaterialService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Master.SeriesService>().As <ACS.Services.Master.ISeriesService>().InstancePerLifetimeScope();
            //ended Suranjana

            //Added by Suranjana 14/07/2016
            builder.RegisterType <ACS.Services.Master.PubCenterService>().As <ACS.Services.Master.IPubCenterService>().InstancePerLifetimeScope();
            //ended Suranjana

            //Added by Suranjana 19/07/2016
            builder.RegisterType <ACS.Services.Master.LicenseeService>().As <ACS.Services.Master.ILicenseeService>().InstancePerLifetimeScope();
            builder.RegisterType <ACS.Services.Master.CopyrightHolderService>().As <ACS.Services.Master.ICopyrightHolderService>().InstancePerLifetimeScope();
            //ended Suranjana

            /*Added by Rajneesh Singh on 01/08/2016*/
            builder.RegisterType <ACS.Services.Product.SeriesProductEntryService>().As <ACS.Services.Product.ISeriesProductEntryService>().InstancePerLifetimeScope();
            /*Ended by Rajneesh Singh*/



            /*Added by Saddam on 27/09/2016*/
            builder.RegisterType <ACS.Services.Alert.ServiceApplicationEmailSetup>().As <ACS.Services.Alert.IServiceApplicationEmailSetup>().InstancePerLifetimeScope();
            /*Ended by Saddam*/

            ////builder.RegisterType<ACS.Services.Directory.GeographyService>().As<ACS.Services.Directory.IGeographyService>().InstancePerLifetimeScope();

            ////builder.RegisterType<ACS.Services.Directory.MasterValueService>().As<ACS.Services.Directory.IMasterValueService>().InstancePerLifetimeScope();

            //////builder.RegisterType<ACS.Services.Contact.VisitorEntryService>().As<ACS.Services.Contact.IVisitorEntryService>().InstancePerLifetimeScope();

            //////builder.RegisterType<TempStaffMasterService>().As<ITempStaffMasterService>().InstancePerLifetimeScope();

            //////builder.RegisterType<StaffMasterService>().As<IStaffMasterService>().InstancePerLifetimeScope();

            //////builder.RegisterType<SocietyService>().As<ISocietyService>().InstancePerLifetimeScope();

            //builder.RegisterType<WorkflowMessageService>().As<IWorkflowMessageService>().InstancePerLifetimeScope();

            //builder.RegisterType<MessageTokenProvider>().As<IMessageTokenProvider>().InstancePerLifetimeScope();

            //builder.RegisterType<MessageTemplateService>().As<IMessageTemplateService>().InstancePerLifetimeScope();

            //builder.RegisterType<QueuedEmailService>().As<IQueuedEmailService>().InstancePerLifetimeScope();

            //builder.RegisterType<Tokenizer>().As<ITokenizer>().InstancePerLifetimeScope();

            //builder.RegisterType<EmailAccountService>().As<IEmailAccountService>().InstancePerLifetimeScope();

            //////builder.RegisterType<VehicleDetailService>().As<IVehicleDetailService>().InstancePerLifetimeScope();
            //////builder.RegisterType<AssetMasterService>().As<IAssetMasterService>().InstancePerLifetimeScope();

            //////builder.RegisterType<AssetAttributeService>().As<IAssetAttributeService>().InstancePerLifetimeScope();
            //////builder.RegisterType<AssetAttributeValueService>().As<IAssetAttributeValueService>().InstancePerLifetimeScope();
            //////builder.RegisterType<SocietyAssetLinkService>().As<ISocietyAssetLinkService>().InstancePerLifetimeScope();
            //////builder.RegisterType<SocietyAssetAttributeValueService>().As<ISocietyAssetAttributeValueService>().InstancePerLifetimeScope();
            //////builder.RegisterType<SocietyAssetImageService>().As<ISocietyAssetImageService>().InstancePerLifetimeScope();


            //builder.RegisterType<CurrencyService>().As<ICurrencyService>().InstancePerLifetimeScope();
            //builder.RegisterType<MeasureService>().As<IMeasureService>().InstancePerLifetimeScope();
            //builder.RegisterType<StateProvinceService>().As<IStateProvinceService>().InstancePerLifetimeScope();

            //builder.RegisterType<StoreService>().As<IStoreService>().InstancePerLifetimeScope();
            ////pass MemoryCacheManager as cacheManager (cache settings between requests)
            //builder.RegisterType<StoreMappingService>().As<IStoreMappingService>()
            //    .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
            //    .InstancePerLifetimeScope();

            //builder.RegisterType<DiscountService>().As<IDiscountService>().InstancePerLifetimeScope();


            //pass MemoryCacheManager as cacheManager (cache settings between requests)
            builder.RegisterType <SettingService>().As <ISettingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());

            ////pass MemoryCacheManager as cacheManager (cache locales between requests)
            builder.RegisterType <LocalizationService>().As <ILocalizationService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            //pass MemoryCacheManager as cacheManager (cache locales between requests)
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();

            //builder.RegisterType<DownloadService>().As<IDownloadService>().InstancePerLifetimeScope();
            //builder.RegisterType<PictureService>().As<IPictureService>().InstancePerLifetimeScope();

            //builder.RegisterType<MessageTemplateService>().As<IMessageTemplateService>().InstancePerLifetimeScope();
            //builder.RegisterType<QueuedEmailService>().As<IQueuedEmailService>().InstancePerLifetimeScope();
            //builder.RegisterType<NewsLetterSubscriptionService>().As<INewsLetterSubscriptionService>().InstancePerLifetimeScope();
            //builder.RegisterType<CampaignService>().As<ICampaignService>().InstancePerLifetimeScope();
            //builder.RegisterType<EmailAccountService>().As<IEmailAccountService>().InstancePerLifetimeScope();
            //builder.RegisterType<WorkflowMessageService>().As<IWorkflowMessageService>().InstancePerLifetimeScope();
            //builder.RegisterType<MessageTokenProvider>().As<IMessageTokenProvider>().InstancePerLifetimeScope();
            //builder.RegisterType<Tokenizer>().As<ITokenizer>().InstancePerLifetimeScope();
            //builder.RegisterType<EmailSender>().As<IEmailSender>().InstancePerLifetimeScope();

            //builder.RegisterType<CheckoutAttributeFormatter>().As<ICheckoutAttributeFormatter>().InstancePerLifetimeScope();
            //builder.RegisterType<CheckoutAttributeParser>().As<ICheckoutAttributeParser>().InstancePerLifetimeScope();
            //builder.RegisterType<CheckoutAttributeService>().As<ICheckoutAttributeService>().InstancePerLifetimeScope();
            //builder.RegisterType<GiftCardService>().As<IGiftCardService>().InstancePerLifetimeScope();
            //builder.RegisterType<OrderService>().As<IOrderService>().InstancePerLifetimeScope();
            //builder.RegisterType<OrderReportService>().As<IOrderReportService>().InstancePerLifetimeScope();
            //builder.RegisterType<OrderProcessingService>().As<IOrderProcessingService>().InstancePerLifetimeScope();
            //builder.RegisterType<OrderTotalCalculationService>().As<IOrderTotalCalculationService>().InstancePerLifetimeScope();
            //builder.RegisterType<ShoppingCartService>().As<IShoppingCartService>().InstancePerLifetimeScope();

            //builder.RegisterType<PaymentService>().As<IPaymentService>().InstancePerLifetimeScope();

            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            //builder.RegisterType<FormsAuthenticationService>().As<IAuthenticationService>().InstancePerLifetimeScope();
            //builder.RegisterType<FlatAuthenticationService>().As<IFlatAuthenticationService>().InstancePerLifetimeScope();


            ////pass MemoryCacheManager as cacheManager (cache settings between requests)
            //builder.RegisterType<UrlRecordService>().As<IUrlRecordService>()
            //    .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
            //    .InstancePerLifetimeScope();

            //builder.RegisterType<ShipmentService>().As<IShipmentService>().InstancePerLifetimeScope();
            //builder.RegisterType<ShippingService>().As<IShippingService>().InstancePerLifetimeScope();

            //builder.RegisterType<TaxCategoryService>().As<ITaxCategoryService>().InstancePerLifetimeScope();
            //builder.RegisterType<TaxService>().As<ITaxService>().InstancePerLifetimeScope();
            //builder.RegisterType<TaxCategoryService>().As<ITaxCategoryService>().InstancePerLifetimeScope();

            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();

            ////pass MemoryCacheManager as cacheManager (cache settings between requests)
            //builder.RegisterType<CustomerActivityService>().As<ICustomerActivityService>()
            //    .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
            //    .InstancePerLifetimeScope();

            //if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["UseFastInstallationService"]) &&
            //    Convert.ToBoolean(ConfigurationManager.AppSettings["UseFastInstallationService"]))
            //{
            //    builder.RegisterType<SqlFileInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
            //}
            //else
            //{
            //    builder.RegisterType<CodeFirstInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
            //}

            //builder.RegisterType<ForumService>().As<IForumService>().InstancePerLifetimeScope();

            //builder.RegisterType<PollService>().As<IPollService>().InstancePerLifetimeScope();
            //builder.RegisterType<BlogService>().As<IBlogService>().InstancePerLifetimeScope();
            //builder.RegisterType<WidgetService>().As<IWidgetService>().InstancePerLifetimeScope();
            //builder.RegisterType<TopicService>().As<ITopicService>().InstancePerLifetimeScope();
            //builder.RegisterType<NewsService>().As<INewsService>().InstancePerLifetimeScope();

            //builder.RegisterType<DateTimeHelper>().As<IDateTimeHelper>().InstancePerLifetimeScope();
            //builder.RegisterType<SitemapGenerator>().As<ISitemapGenerator>().InstancePerLifetimeScope();
            //builder.RegisterType<PageHeadBuilder>().As<IPageHeadBuilder>().InstancePerLifetimeScope();

            ////// builder.RegisterType<ScheduleTaskService>().As<IScheduleTaskService>().InstancePerLifetimeScope();

            //builder.RegisterType<ExportManager>().As<IExportManager>().InstancePerLifetimeScope();
            //builder.RegisterType<ImportManager>().As<IImportManager>().InstancePerLifetimeScope();
            //builder.RegisterType<PdfService>().As<IPdfService>().InstancePerLifetimeScope();
            //builder.RegisterType<ThemeProvider>().As<IThemeProvider>().InstancePerLifetimeScope();
            //builder.RegisterType<ThemeContext>().As<IThemeContext>().InstancePerLifetimeScope();


            //builder.RegisterType<ExternalAuthorizer>().As<IExternalAuthorizer>().InstancePerLifetimeScope();
            //builder.RegisterType<OpenAuthenticationService>().As<IOpenAuthenticationService>().InstancePerLifetimeScope();


            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();

            ////Register event consumers
            //var consumers = typeFinder.FindClassesOfType(typeof(IConsumer<>)).ToList();
            //foreach (var consumer in consumers)
            //{
            //    builder.RegisterType(consumer)
            //        .As(consumer.FindInterfaces((type, criteria) =>
            //        {
            //            var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
            //            return isMatch;
            //        }, typeof(IConsumer<>)))
            //        .InstancePerLifetimeScope();
            //}
            //builder.RegisterType<EventPublisher>().As<IEventPublisher>().SingleInstance();
            //builder.RegisterType<SubscriptionService>().As<ISubscriptionService>().SingleInstance();
        }
示例#22
0
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             //register FakeHttpContext when HttpContext is not available
                             HttpContext.Current != null ?
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
                             (new FakeHttpContext("~/") as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerHttpRequest();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerHttpRequest();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerHttpRequest();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerHttpRequest();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerHttpRequest();

            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerHttpRequest();

            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();


            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerHttpRequest();
            }
            else
            {
                builder.Register <IDbContext>(c => new NopObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerHttpRequest();
            }


            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerHttpRequest();

            //plugins
            builder.RegisterType <PluginFinder>().As <IPluginFinder>().InstancePerHttpRequest();

            //cache manager
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_static").SingleInstance();
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_per_request").InstancePerHttpRequest();


            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerHttpRequest();
            //store context
            builder.RegisterType <WebStoreContext>().As <IStoreContext>().InstancePerHttpRequest();

            //services
            builder.RegisterType <BackInStockSubscriptionService>().As <IBackInStockSubscriptionService>().InstancePerHttpRequest();
            builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerHttpRequest();
            builder.RegisterType <CompareProductsService>().As <ICompareProductsService>().InstancePerHttpRequest();
            builder.RegisterType <RecentlyViewedProductsService>().As <IRecentlyViewedProductsService>().InstancePerHttpRequest();
            builder.RegisterType <ManufacturerService>().As <IManufacturerService>().InstancePerHttpRequest();
            builder.RegisterType <PriceCalculationService>().As <IPriceCalculationService>().InstancePerHttpRequest();
            builder.RegisterType <PriceFormatter>().As <IPriceFormatter>().InstancePerHttpRequest();
            builder.RegisterType <ProductAttributeFormatter>().As <IProductAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <ProductAttributeParser>().As <IProductAttributeParser>().InstancePerHttpRequest();
            builder.RegisterType <ProductAttributeService>().As <IProductAttributeService>().InstancePerHttpRequest();
            builder.RegisterType <ProductService>().As <IProductService>().InstancePerHttpRequest();
            builder.RegisterType <CopyProductService>().As <ICopyProductService>().InstancePerHttpRequest();
            builder.RegisterType <SpecificationAttributeService>().As <ISpecificationAttributeService>().InstancePerHttpRequest();
            builder.RegisterType <ProductTemplateService>().As <IProductTemplateService>().InstancePerHttpRequest();
            builder.RegisterType <CategoryTemplateService>().As <ICategoryTemplateService>().InstancePerHttpRequest();
            builder.RegisterType <ManufacturerTemplateService>().As <IManufacturerTemplateService>().InstancePerHttpRequest();
            //pass MemoryCacheManager as cacheManager (cache settings between requests)
            builder.RegisterType <ProductTagService>().As <IProductTagService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerHttpRequest();

            builder.RegisterType <AffiliateService>().As <IAffiliateService>().InstancePerHttpRequest();
            builder.RegisterType <VendorService>().As <IVendorService>().InstancePerHttpRequest();
            builder.RegisterType <AddressService>().As <IAddressService>().InstancePerHttpRequest();
            builder.RegisterType <SearchTermService>().As <ISearchTermService>().InstancePerHttpRequest();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerHttpRequest();
            builder.RegisterType <FulltextService>().As <IFulltextService>().InstancePerHttpRequest();
            builder.RegisterType <MaintenanceService>().As <IMaintenanceService>().InstancePerHttpRequest();

            builder.RegisterType <CustomerLeadService>().As <ICustomerLeadService>().InstancePerHttpRequest();
            builder.RegisterType <SharingPartnerLevelService>().As <ISharingPartnerLevelService>().InstancePerHttpRequest();
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerHttpRequest();
            builder.RegisterType <CustomerRegistrationService>().As <ICustomerRegistrationService>().InstancePerHttpRequest();
            builder.RegisterType <CustomerReportService>().As <ICustomerReportService>().InstancePerHttpRequest();

            //pass MemoryCacheManager as cacheManager (cache settings between requests)
            builder.RegisterType <PermissionService>().As <IPermissionService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerHttpRequest();
            //pass MemoryCacheManager as cacheManager (cache settings between requests)
            builder.RegisterType <AclService>().As <IAclService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerHttpRequest();

            builder.RegisterType <GeoLookupService>().As <IGeoLookupService>().InstancePerHttpRequest();
            builder.RegisterType <CountryService>().As <ICountryService>().InstancePerHttpRequest();
            builder.RegisterType <CurrencyService>().As <ICurrencyService>().InstancePerHttpRequest();
            builder.RegisterType <MeasureService>().As <IMeasureService>().InstancePerHttpRequest();
            builder.RegisterType <StateProvinceService>().As <IStateProvinceService>().InstancePerHttpRequest();

            builder.RegisterType <StoreService>().As <IStoreService>().InstancePerHttpRequest();
            //pass MemoryCacheManager as cacheManager (cache settings between requests)
            builder.RegisterType <StoreMappingService>().As <IStoreMappingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerHttpRequest();

            builder.RegisterType <DiscountService>().As <IDiscountService>().InstancePerHttpRequest();


            //pass MemoryCacheManager as cacheManager (cache settings between requests)
            builder.RegisterType <SettingService>().As <ISettingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerHttpRequest();
            builder.RegisterSource(new SettingsSource());

            //pass MemoryCacheManager as cacheManager (cache locales between requests)
            builder.RegisterType <LocalizationService>().As <ILocalizationService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerHttpRequest();

            //pass MemoryCacheManager as cacheManager (cache locales between requests)
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerHttpRequest();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerHttpRequest();

            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerHttpRequest();
            builder.RegisterType <PictureService>().As <IPictureService>().InstancePerHttpRequest();

            builder.RegisterType <MessageTemplateService>().As <IMessageTemplateService>().InstancePerHttpRequest();
            builder.RegisterType <QueuedEmailService>().As <IQueuedEmailService>().InstancePerHttpRequest();
            builder.RegisterType <NewsLetterSubscriptionService>().As <INewsLetterSubscriptionService>().InstancePerHttpRequest();
            builder.RegisterType <CampaignService>().As <ICampaignService>().InstancePerHttpRequest();
            builder.RegisterType <EmailAccountService>().As <IEmailAccountService>().InstancePerHttpRequest();
            builder.RegisterType <WorkflowMessageService>().As <IWorkflowMessageService>().InstancePerHttpRequest();
            builder.RegisterType <MessageTokenProvider>().As <IMessageTokenProvider>().InstancePerHttpRequest();
            builder.RegisterType <Tokenizer>().As <ITokenizer>().InstancePerHttpRequest();
            builder.RegisterType <EmailSender>().As <IEmailSender>().InstancePerHttpRequest();

            builder.RegisterType <CheckoutAttributeFormatter>().As <ICheckoutAttributeFormatter>().InstancePerHttpRequest();
            builder.RegisterType <CheckoutAttributeParser>().As <ICheckoutAttributeParser>().InstancePerHttpRequest();
            builder.RegisterType <CheckoutAttributeService>().As <ICheckoutAttributeService>().InstancePerHttpRequest();
            builder.RegisterType <GiftCardService>().As <IGiftCardService>().InstancePerHttpRequest();
            builder.RegisterType <OrderService>().As <IOrderService>().InstancePerHttpRequest();
            builder.RegisterType <OrderReportService>().As <IOrderReportService>().InstancePerHttpRequest();
            builder.RegisterType <OrderProcessingService>().As <IOrderProcessingService>().InstancePerHttpRequest();
            builder.RegisterType <OrderTotalCalculationService>().As <IOrderTotalCalculationService>().InstancePerHttpRequest();
            builder.RegisterType <ShoppingCartService>().As <IShoppingCartService>().InstancePerHttpRequest();

            builder.RegisterType <PaymentService>().As <IPaymentService>().InstancePerHttpRequest();

            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerHttpRequest();
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerHttpRequest();


            //pass MemoryCacheManager as cacheManager (cache settings between requests)
            builder.RegisterType <UrlRecordService>().As <IUrlRecordService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerHttpRequest();

            builder.RegisterType <ShipmentService>().As <IShipmentService>().InstancePerHttpRequest();
            builder.RegisterType <ShippingService>().As <IShippingService>().InstancePerHttpRequest();

            builder.RegisterType <TaxCategoryService>().As <ITaxCategoryService>().InstancePerHttpRequest();
            builder.RegisterType <TaxService>().As <ITaxService>().InstancePerHttpRequest();
            builder.RegisterType <TaxCategoryService>().As <ITaxCategoryService>().InstancePerHttpRequest();

            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerHttpRequest();
            builder.RegisterType <CustomerActivityService>().As <ICustomerActivityService>().InstancePerHttpRequest();

            if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["UseFastInstallationService"]) &&
                Convert.ToBoolean(ConfigurationManager.AppSettings["UseFastInstallationService"]))
            {
                builder.RegisterType <SqlFileInstallationService>().As <IInstallationService>().InstancePerHttpRequest();
            }
            else
            {
                builder.RegisterType <CodeFirstInstallationService>().As <IInstallationService>().InstancePerHttpRequest();
            }

            builder.RegisterType <ForumService>().As <IForumService>().InstancePerHttpRequest();

            builder.RegisterType <PollService>().As <IPollService>().InstancePerHttpRequest();
            builder.RegisterType <BlogService>().As <IBlogService>().InstancePerHttpRequest();
            builder.RegisterType <WidgetService>().As <IWidgetService>().InstancePerHttpRequest();
            builder.RegisterType <TopicService>().As <ITopicService>().InstancePerHttpRequest();
            builder.RegisterType <NewsService>().As <INewsService>().InstancePerHttpRequest();


            builder.RegisterType <DateTimeHelper>().As <IDateTimeHelper>().InstancePerHttpRequest();
            builder.RegisterType <SitemapGenerator>().As <ISitemapGenerator>().InstancePerHttpRequest();
            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerHttpRequest();

            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerHttpRequest();

            builder.RegisterType <TelerikLocalizationServiceFactory>().As <Telerik.Web.Mvc.Infrastructure.ILocalizationServiceFactory>().InstancePerHttpRequest();

            builder.RegisterType <ExportManager>().As <IExportManager>().InstancePerHttpRequest();
            builder.RegisterType <ImportManager>().As <IImportManager>().InstancePerHttpRequest();
            builder.RegisterType <MobileDeviceHelper>().As <IMobileDeviceHelper>().InstancePerHttpRequest();
            builder.RegisterType <PdfService>().As <IPdfService>().InstancePerHttpRequest();
            builder.RegisterType <ThemeProvider>().As <IThemeProvider>().InstancePerHttpRequest();
            builder.RegisterType <ThemeContext>().As <IThemeContext>().InstancePerHttpRequest();


            builder.RegisterType <ExternalAuthorizer>().As <IExternalAuthorizer>().InstancePerHttpRequest();
            builder.RegisterType <OpenAuthenticationService>().As <IOpenAuthenticationService>().InstancePerHttpRequest();


            builder.RegisterType <EmbeddedViewResolver>().As <IEmbeddedViewResolver>().SingleInstance();
            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();

            //HTML Editor services
            builder.RegisterType <NetAdvDirectoryService>().As <INetAdvDirectoryService>().InstancePerHttpRequest();
            builder.RegisterType <NetAdvImageService>().As <INetAdvImageService>().InstancePerHttpRequest();

            //Register event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerHttpRequest();
            }
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
        }
示例#23
0
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             new HttpContextWrapper(HttpContext.Current) as HttpContextBase)
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();

            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();
            //user agent helper

            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();

            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new EdenObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new EdenObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            builder.RegisterGeneric(typeof(DefaultEntityService <>)).As(typeof(IEntityService <>)).InstancePerLifetimeScope();

            //cache manager
            //builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().Named<ICacheManager>("sxg_cache_static").SingleInstance();
            //builder.RegisterType<PerRequestCacheManager>().As<ICacheManager>().Named<ICacheManager>("sxg_cache_per_request").InstancePerLifetimeScope();
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().SingleInstance();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();


            //task
            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();

            builder.RegisterType <AqiGradeService>().As <IAqiGradeService>().InstancePerLifetimeScope();
            builder.RegisterType <RestAqiManager>().As <IAqiManager>().InstancePerLifetimeScope();

            builder.RegisterType <SiteService>().As <ISiteService>().InstancePerLifetimeScope();

            builder.RegisterType <DeviceService>().As <IDeviceService>().InstancePerLifetimeScope();

            builder.RegisterType <JPush>().As <IPushService>().InstancePerLifetimeScope();

            builder.RegisterType <NotifyService>().As <INotifyService>().InstancePerLifetimeScope();
        }
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, ArticleConfig config)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             //register FakeHttpContext when HttpContext is not available
                             HttpContext.Current != null ?
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
                             (new FakeHttpContext("~/") as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();

            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();
            //user agent helper

            //controllers
            // builder.Register(c => new CacheIInterceptor());
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer

            builder.Register(x => new EfDataProviderManager(config)).As <BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            var efDataProviderManager = new EfDataProviderManager(config);
            var dataProvider          = efDataProviderManager.LoadDataProvider();

            dataProvider.InitDatabase(config.DatabaseInstallModel);

            builder.Register <IDbContext>(c => new BaseObjectContext(config.MsSqlConnectionString)).InstancePerLifetimeScope();
            //builder.Register<IWriteDbContext>(c => new WriteObjectContext(config.MsSqlWriteConnectionString)).InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            //cache managers
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().SingleInstance();

            //services

            //use static cache (between HTTP requests)
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <DbContextFactory>().As <IDbContextFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SingleStrategy>().As <IReadDbStrategy>().InstancePerLifetimeScope();
            //use static cache (between HTTP requests)

            bool databaseInstalled = DataSettingsHelper.DatabaseIsInstalled(config);

            if (!databaseInstalled)
            {
                //builder.RegisterType<CodeFirstInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
                //installation service
                //if (config.UseFastInstallationService)
                //{
                //    builder.RegisterType<SqlFileInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
                //}
                //else
                //{
                //    builder.RegisterType<CodeFirstInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
                //}
            }

            //Register event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().InstancePerLifetimeScope();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().InstancePerLifetimeScope();

            //unit of work
            builder.RegisterType <UnitOfWorkDbContextProvider>().As <IDbContextProvider>().InstancePerLifetimeScope();
            builder.RegisterType <CallContextCurrentUnitOfWorkProvider>().As <IUnitOfWorkProvider>().InstancePerLifetimeScope();
            builder.RegisterType <EfUnitOfWork>().As <IUnitOfWork>().InstancePerLifetimeScope();
            builder.RegisterType <UnitOfWorkManager>().As <IUnitOfWorkManager>().InstancePerLifetimeScope();
            builder.RegisterType <DbContextEfTransactionStrategy>().As <IEfTransactionStrategy>().InstancePerLifetimeScope();
            builder.RegisterType <CallContextAmbientDataContext>().As <IAmbientDataContext>().SingleInstance();
            builder.RegisterGeneric(typeof(DataContextAmbientScopeProvider <>)).As(typeof(IAmbientScopeProvider <>)).InstancePerLifetimeScope();

            //serivce

            //Article
            builder.RegisterType <PayService>().As <IPayService>().InstancePerLifetimeScope().EnableClassInterceptors();

            //Auth
            builder.RegisterType <RoomService>().As <IRoomService>().InstancePerLifetimeScope().EnableClassInterceptors();

            //Author
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope().EnableClassInterceptors();

            //CounterService
            builder.RegisterType <SysService>().As <ISysService>().InstancePerLifetimeScope().EnableClassInterceptors();

            //CounterService


            builder.RegisterType <RedisCacheManager>().As <IRedis>().InstancePerLifetimeScope();
        }
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             //register FakeHttpContext when HttpContext is not available
                             HttpContext.Current != null ?
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
                             (new FakeHttpContext("~/") as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();

            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();

            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());


            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();
            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();
                builder.Register <IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new NopObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            // 注入ef到仓储
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();


            //log
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();

            //cache managers
            if (config != null && config.RedisCachingEnabled)
            {
                builder.RegisterType <RedisConnectionWrapper>().As <IRedisConnectionWrapper>().SingleInstance();
                builder.RegisterType <RedisCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_static").InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_static").SingleInstance();
            }
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_per_request").InstancePerLifetimeScope();

            // 注入Service及接口
            //builder.RegisterAssemblyTypes(typeof(TestService).Assembly)
            //        .AsImplementedInterfaces()
            //        .InstancePerLifetimeScope();

            builder.RegisterType <UserActivityService>().As <IUserActivityService>().InstancePerLifetimeScope();


            //use static cache (between HTTP requests)
            builder.RegisterType <SettingService>().As <ISettingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());
        }
示例#26
0
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, ACConfig config)
        {
            // HttpContext
            builder.Register(c =>
                             new HttpContextWrapper(HttpContext.Current) as HttpContextBase).As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();

            // web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();

            // controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            // data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();

            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new ACObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new ACObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            builder.RegisterGeneric(typeof(GenericRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            // work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();

            // services
            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope();
            builder.RegisterType <TopicService>().As <ITopicService>().InstancePerLifetimeScope();
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerLifetimeScope();
            builder.RegisterType <ItemService>().As <IItemService>().InstancePerLifetimeScope();
            builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();
            builder.RegisterType <ShoppingCartService>().As <IShoppingCartService>().InstancePerLifetimeScope();
            builder.RegisterType <OrderService>().As <IOrderService>().InstancePerLifetimeScope();
            builder.RegisterType <UserRegistrationService>().As <IUserRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();

            builder.RegisterType <LocalizationService>().As <ILocalizationService>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
        }
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             //register FakeHttpContext when HttpContext is not available
                             HttpContext.Current != null ?
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
                             (new FakeHttpContext("~/") as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();

            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();
            //user agent helper
            builder.RegisterType <UserAgentHelper>().As <IUserAgentHelper>().InstancePerLifetimeScope();


            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();


            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new NopObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }


            builder.RegisterGeneric(typeof(StringKeyRepository <>)).As(typeof(IStringKeyRepository <>)).InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            //plugins
            builder.RegisterType <PluginFinder>().As <IPluginFinder>().InstancePerLifetimeScope();
            builder.RegisterType <OfficialFeedManager>().As <IOfficialFeedManager>().InstancePerLifetimeScope();

            //cache managers
            if (config.RedisCachingEnabled)
            {
                builder.RegisterType <RedisConnectionWrapper>().As <IRedisConnectionWrapper>().SingleInstance();
                builder.RegisterType <RedisCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_static").InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_static").SingleInstance();
            }
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_per_request").InstancePerLifetimeScope();

            if (config.RunOnAzureWebApps)
            {
                builder.RegisterType <AzureWebAppsMachineNameProvider>().As <IMachineNameProvider>().SingleInstance();
            }
            else
            {
                builder.RegisterType <DefaultMachineNameProvider>().As <IMachineNameProvider>().SingleInstance();
            }

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();
            //store context
            builder.RegisterType <WebStoreContext>().As <IStoreContext>().InstancePerLifetimeScope();

            //services

            #region Moveleiros

            builder.RegisterType <BrandService>().As <IBrandService>().InstancePerLifetimeScope();
            builder.RegisterType <CityService>().As <ICityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            builder.RegisterType <LivechatService>().As <ILivechatService>().InstancePerLifetimeScope();

            #endregion

            builder.RegisterType <BackInStockSubscriptionService>().As <IBackInStockSubscriptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerLifetimeScope();
            builder.RegisterType <CompareProductsService>().As <ICompareProductsService>().InstancePerLifetimeScope();
            builder.RegisterType <RecentlyViewedProductsService>().As <IRecentlyViewedProductsService>().InstancePerLifetimeScope();
            builder.RegisterType <ManufacturerService>().As <IManufacturerService>().InstancePerLifetimeScope();
            builder.RegisterType <PriceFormatter>().As <IPriceFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <ProductAttributeFormatter>().As <IProductAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <ProductAttributeParser>().As <IProductAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <ProductAttributeService>().As <IProductAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <ProductService>().As <IProductService>().InstancePerLifetimeScope();
            builder.RegisterType <CopyProductService>().As <ICopyProductService>().InstancePerLifetimeScope();
            builder.RegisterType <SpecificationAttributeService>().As <ISpecificationAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <ProductTemplateService>().As <IProductTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryTemplateService>().As <ICategoryTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <ManufacturerTemplateService>().As <IManufacturerTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <TopicTemplateService>().As <ITopicTemplateService>().InstancePerLifetimeScope();
            //use static cache (between HTTP requests)
            builder.RegisterType <ProductTagService>().As <IProductTagService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            builder.RegisterType <AddressAttributeFormatter>().As <IAddressAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeParser>().As <IAddressAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeService>().As <IAddressAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <AddressService>().As <IAddressService>().InstancePerLifetimeScope();
            builder.RegisterType <AffiliateService>().As <IAffiliateService>().InstancePerLifetimeScope();
            builder.RegisterType <VendorService>().As <IVendorService>().InstancePerLifetimeScope();
            builder.RegisterType <SearchTermService>().As <ISearchTermService>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <FulltextService>().As <IFulltextService>().InstancePerLifetimeScope();
            builder.RegisterType <MaintenanceService>().As <IMaintenanceService>().InstancePerLifetimeScope();

            builder.RegisterType <CustomerAttributeFormatter>().As <ICustomerAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeParser>().As <ICustomerAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeService>().As <ICustomerAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRegistrationService>().As <ICustomerRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReportService>().As <ICustomerReportService>().InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <PermissionService>().As <IPermissionService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            //use static cache (between HTTP requests)
            builder.RegisterType <AclService>().As <IAclService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            //use static cache (between HTTP requests)
            builder.RegisterType <PriceCalculationService>().As <IPriceCalculationService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            builder.RegisterType <GeoLookupService>().As <IGeoLookupService>().InstancePerLifetimeScope();
            builder.RegisterType <CountryService>().As <ICountryService>().InstancePerLifetimeScope();
            builder.RegisterType <CurrencyService>().As <ICurrencyService>().InstancePerLifetimeScope();
            builder.RegisterType <MeasureService>().As <IMeasureService>().InstancePerLifetimeScope();
            builder.RegisterType <StateProvinceService>().As <IStateProvinceService>().InstancePerLifetimeScope();

            builder.RegisterType <StoreService>().As <IStoreService>().InstancePerLifetimeScope();
            //use static cache (between HTTP requests)
            builder.RegisterType <StoreMappingService>().As <IStoreMappingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <DiscountService>().As <IDiscountService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <SettingService>().As <ISettingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());

            //use static cache (between HTTP requests)
            builder.RegisterType <LocalizationService>().As <ILocalizationService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();

            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope();
            //picture service
            var useAzureBlobStorage = !String.IsNullOrEmpty(config.AzureBlobStorageConnectionString);
            if (useAzureBlobStorage)
            {
                //Windows Azure BLOB
                builder.RegisterType <AzurePictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }
            else
            {
                //standard file system
                builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }

            builder.RegisterType <MessageTemplateService>().As <IMessageTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailService>().As <IQueuedEmailService>().InstancePerLifetimeScope();
            builder.RegisterType <NewsLetterSubscriptionService>().As <INewsLetterSubscriptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CampaignService>().As <ICampaignService>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountService>().As <IEmailAccountService>().InstancePerLifetimeScope();
            builder.RegisterType <WorkflowMessageService>().As <IWorkflowMessageService>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTokenProvider>().As <IMessageTokenProvider>().InstancePerLifetimeScope();
            builder.RegisterType <Tokenizer>().As <ITokenizer>().InstancePerLifetimeScope();
            builder.RegisterType <EmailSender>().As <IEmailSender>().InstancePerLifetimeScope();

            builder.RegisterType <CheckoutAttributeFormatter>().As <ICheckoutAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <CheckoutAttributeParser>().As <ICheckoutAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <CheckoutAttributeService>().As <ICheckoutAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <GiftCardService>().As <IGiftCardService>().InstancePerLifetimeScope();
            builder.RegisterType <OrderService>().As <IOrderService>().InstancePerLifetimeScope();
            builder.RegisterType <OrderReportService>().As <IOrderReportService>().InstancePerLifetimeScope();
            builder.RegisterType <OrderProcessingService>().As <IOrderProcessingService>().InstancePerLifetimeScope();
            builder.RegisterType <OrderTotalCalculationService>().As <IOrderTotalCalculationService>().InstancePerLifetimeScope();
            builder.RegisterType <ReturnRequestService>().As <IReturnRequestService>().InstancePerLifetimeScope();
            builder.RegisterType <RewardPointService>().As <IRewardPointService>().InstancePerLifetimeScope();
            builder.RegisterType <ShoppingCartService>().As <IShoppingCartService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomNumberFormatter>().As <ICustomNumberFormatter>().InstancePerLifetimeScope();

            builder.RegisterType <ProjectService>().As <IProjectService>().InstancePerLifetimeScope();

            builder.RegisterType <PaymentService>().As <IPaymentService>().InstancePerLifetimeScope();

            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();


            //use static cache (between HTTP requests)
            builder.RegisterType <UrlRecordService>().As <IUrlRecordService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            // Moveleiros
            // KeywordsMappingService
            builder.RegisterType <KeywordsMappingService>().As <IKeywordsMappingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            builder.RegisterType <ShipmentService>().As <IShipmentService>().InstancePerLifetimeScope();
            builder.RegisterType <ShippingService>().As <IShippingService>().InstancePerLifetimeScope();
            builder.RegisterType <DateRangeService>().As <IDateRangeService>().InstancePerLifetimeScope();

            builder.RegisterType <TaxCategoryService>().As <ITaxCategoryService>().InstancePerLifetimeScope();
            builder.RegisterType <TaxService>().As <ITaxService>().InstancePerLifetimeScope();

            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <CustomerActivityService>().As <ICustomerActivityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            bool databaseInstalled = DataSettingsHelper.DatabaseIsInstalled();
            if (!databaseInstalled)
            {
                //installation service
                if (config.UseFastInstallationService)
                {
                    builder.RegisterType <SqlFileInstallationService>().As <IInstallationService>().InstancePerLifetimeScope();
                }
                else
                {
                    builder.RegisterType <CodeFirstInstallationService>().As <IInstallationService>().InstancePerLifetimeScope();
                }
            }

            builder.RegisterType <ForumService>().As <IForumService>().InstancePerLifetimeScope();

            builder.RegisterType <PollService>().As <IPollService>().InstancePerLifetimeScope();
            builder.RegisterType <BlogService>().As <IBlogService>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetService>().As <IWidgetService>().InstancePerLifetimeScope();
            builder.RegisterType <TopicService>().As <ITopicService>().InstancePerLifetimeScope();
            builder.RegisterType <NewsService>().As <INewsService>().InstancePerLifetimeScope();

            builder.RegisterType <DateTimeHelper>().As <IDateTimeHelper>().InstancePerLifetimeScope();
            builder.RegisterType <SitemapGenerator>().As <ISitemapGenerator>().InstancePerLifetimeScope();
            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope();

            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();

            builder.RegisterType <ExportManager>().As <IExportManager>().InstancePerLifetimeScope();
            builder.RegisterType <ImportManager>().As <IImportManager>().InstancePerLifetimeScope();
            builder.RegisterType <PdfService>().As <IPdfService>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeProvider>().As <IThemeProvider>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeContext>().As <IThemeContext>().InstancePerLifetimeScope();


            builder.RegisterType <ExternalAuthorizer>().As <IExternalAuthorizer>().InstancePerLifetimeScope();
            builder.RegisterType <OpenAuthenticationService>().As <IOpenAuthenticationService>().InstancePerLifetimeScope();


            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();

            //Register event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();
            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
        }
示例#28
0
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, WeiConfig config)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();
            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());
            builder.RegisterApiControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();


            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new WeiObjectContext("DefaultConnection")).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new WeiObjectContext("DefaultConnection")).InstancePerLifetimeScope();
            }


            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("wei_cache_static").SingleInstance();
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("wei_cache_per_request").InstancePerLifetimeScope();

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();
            builder.RegisterType <DBHelp>().As <DBHelp>().InstancePerLifetimeScope();


            builder.RegisterType <CommonService>().As <ICommonService>().InstancePerLifetimeScope();
            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope();
            builder.RegisterType <PropertyService>().As <IPropertyService>().InstancePerLifetimeScope();
            builder.RegisterType <WordsSubstitutionService>().As <IWordsSubstitutionService>().InstancePerLifetimeScope();
            builder.RegisterType <DBService>().As <IDBService>().InstancePerLifetimeScope();
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <UserAttributeService>().As <IUserAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UserRegistrationService>().As <IUserRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();

            builder.RegisterType <UserAnswerService>().As <IUserAnswerService>().InstancePerLifetimeScope();
            builder.RegisterType <QuestionBankService>().As <IQuestionBankService>().InstancePerLifetimeScope();

            //Register event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
        }
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             //register FakeHttpContext when HttpContext is not available
                             HttpContext.Current != null ?
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
                             (new FakeHttpContext("~/") as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();

            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();

            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());


            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();
            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();
            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();
                builder.Register <IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new NopObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            // 注入ef到仓储
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();


            //log
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();

            //cache managers
            if (config != null && config.RedisCachingEnabled)
            {
                builder.RegisterType <RedisConnectionWrapper>().As <IRedisConnectionWrapper>().SingleInstance();
                builder.RegisterType <RedisCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_static").InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_static").SingleInstance();
            }
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_per_request").InstancePerLifetimeScope();

            // 注入Service及接口
            //builder.RegisterAssemblyTypes(typeof(TestService).Assembly)
            //        .AsImplementedInterfaces()
            //        .InstancePerLifetimeScope();
            builder.RegisterType <UserActivityService>().As <IUserActivityService>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizationService>().As <ILocalizationService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>().InstancePerLifetimeScope();


            builder.RegisterType <UserAttributeFormatter>().As <IUserAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <UserAttributeParser>().As <IUserAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <UserAttributeService>().As <IUserAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <UserRegistrationService>().As <IUserRegistrationService>().InstancePerLifetimeScope();
            //builder.RegisterType<UserReportService>().As<IUserReportService>().InstancePerLifetimeScope();

            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <DateTimeHelper>().As <IDateTimeHelper>().InstancePerLifetimeScope();


            builder.RegisterType <ExternalAuthorizer>().As <IExternalAuthorizer>().InstancePerLifetimeScope();
            builder.RegisterType <OpenAuthenticationService>().As <IOpenAuthenticationService>().InstancePerLifetimeScope();



            //use static cache (between HTTP requests)
            builder.RegisterType <SettingService>().As <ISettingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());


            //builder.RegisterType<PageHeadBuilder>().As<IPageHeadBuilder>().InstancePerLifetimeScope();

            //Register event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
        }
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();

            //user agent helper
            builder.RegisterType <UserAgentHelper>().As <IUserAgentHelper>().InstancePerLifetimeScope();

            //data layer
            // var dataSettingsManager = new DataSettingsManager();
            //var dataProviderSettings = dataSettingsManager.LoadSettings();
            //builder.Register(c => dataSettingsManager.LoadSettings()).As<DataSettings>();
            builder.Register(x => new EfDataProviderManager()).As <BaseDataProviderManager>().InstancePerDependency();

            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            //if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager();
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new NopObjectContext(ConfigSetting.DataConnectionString)).InstancePerLifetimeScope();
            }
            //else
            //    builder.Register<IDbContext>(c => new NopObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();

            //repositories
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            //plugins
            builder.RegisterType <PluginFinder>().As <IPluginFinder>().InstancePerLifetimeScope();
            builder.RegisterType <OfficialFeedManager>().As <IOfficialFeedManager>().InstancePerLifetimeScope();

            //cache manager
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().InstancePerLifetimeScope();

            //static cache manager
            if (config.RedisCachingEnabled)
            {
                builder.RegisterType <RedisConnectionWrapper>().As <IRedisConnectionWrapper>().SingleInstance();
                builder.RegisterType <RedisCacheManager>().As <IStaticCacheManager>().InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>().As <IStaticCacheManager>().SingleInstance();
            }

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();

            //store context
            //builder.RegisterType<WebStoreContext>().As<IStoreContext>().InstancePerLifetimeScope();

            //services
            builder.RegisterType <BackInStockSubscriptionService>().As <IBackInStockSubscriptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerLifetimeScope();
            builder.RegisterType <CompareProductsService>().As <ICompareProductsService>().InstancePerLifetimeScope();
            builder.RegisterType <RecentlyViewedProductsService>().As <IRecentlyViewedProductsService>().InstancePerLifetimeScope();
            builder.RegisterType <ManufacturerService>().As <IManufacturerService>().InstancePerLifetimeScope();
            builder.RegisterType <PriceFormatter>().As <IPriceFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <ProductAttributeFormatter>().As <IProductAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <ProductAttributeParser>().As <IProductAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <ProductAttributeService>().As <IProductAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <ProductService>().As <IProductService>().InstancePerLifetimeScope();
            builder.RegisterType <CopyProductService>().As <ICopyProductService>().InstancePerLifetimeScope();
            builder.RegisterType <SpecificationAttributeService>().As <ISpecificationAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <ProductTemplateService>().As <IProductTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryTemplateService>().As <ICategoryTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <ManufacturerTemplateService>().As <IManufacturerTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <TopicTemplateService>().As <ITopicTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <ProductTagService>().As <IProductTagService>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeFormatter>().As <IAddressAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeParser>().As <IAddressAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeService>().As <IAddressAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <AddressService>().As <IAddressService>().InstancePerLifetimeScope();
            builder.RegisterType <AffiliateService>().As <IAffiliateService>().InstancePerLifetimeScope();
            builder.RegisterType <VendorService>().As <IVendorService>().InstancePerLifetimeScope();
            builder.RegisterType <SearchTermService>().As <ISearchTermService>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <FulltextService>().As <IFulltextService>().InstancePerLifetimeScope();
            builder.RegisterType <MaintenanceService>().As <IMaintenanceService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeFormatter>().As <ICustomerAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeParser>().As <ICustomerAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeService>().As <ICustomerAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRegistrationService>().As <ICustomerRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReportService>().As <ICustomerReportService>().InstancePerLifetimeScope();
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <AclService>().As <IAclService>().InstancePerLifetimeScope();
            builder.RegisterType <PriceCalculationService>().As <IPriceCalculationService>().InstancePerLifetimeScope();
            builder.RegisterType <GeoLookupService>().As <IGeoLookupService>().InstancePerLifetimeScope();
            builder.RegisterType <CountryService>().As <ICountryService>().InstancePerLifetimeScope();
            builder.RegisterType <CurrencyService>().As <ICurrencyService>().InstancePerLifetimeScope();
            builder.RegisterType <MeasureService>().As <IMeasureService>().InstancePerLifetimeScope();
            builder.RegisterType <StateProvinceService>().As <IStateProvinceService>().InstancePerLifetimeScope();
            builder.RegisterType <StoreService>().As <IStoreService>().InstancePerLifetimeScope();
            builder.RegisterType <StoreMappingService>().As <IStoreMappingService>().InstancePerLifetimeScope();
            builder.RegisterType <DiscountService>().As <IDiscountService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizationService>().As <ILocalizationService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();
            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTemplateService>().As <IMessageTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailService>().As <IQueuedEmailService>().InstancePerLifetimeScope();
            builder.RegisterType <NewsLetterSubscriptionService>().As <INewsLetterSubscriptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CampaignService>().As <ICampaignService>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountService>().As <IEmailAccountService>().InstancePerLifetimeScope();
            builder.RegisterType <WorkflowMessageService>().As <IWorkflowMessageService>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTokenProvider>().As <IMessageTokenProvider>().InstancePerLifetimeScope();
            builder.RegisterType <Tokenizer>().As <ITokenizer>().InstancePerLifetimeScope();
            builder.RegisterType <EmailSender>().As <IEmailSender>().InstancePerLifetimeScope();
            builder.RegisterType <CheckoutAttributeFormatter>().As <ICheckoutAttributeFormatter>().InstancePerLifetimeScope();
            //builder.RegisterType<CheckoutAttributeParser>().As<ICheckoutAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <CheckoutAttributeService>().As <ICheckoutAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <GiftCardService>().As <IGiftCardService>().InstancePerLifetimeScope();
            builder.RegisterType <OrderService>().As <IOrderService>().InstancePerLifetimeScope();
            builder.RegisterType <OrderReportService>().As <IOrderReportService>().InstancePerLifetimeScope();
            // builder.RegisterType<OrderProcessingService>().As<IOrderProcessingService>().InstancePerLifetimeScope();
            //builder.RegisterType<OrderTotalCalculationService>().As<IOrderTotalCalculationService>().InstancePerLifetimeScope();
            builder.RegisterType <ReturnRequestService>().As <IReturnRequestService>().InstancePerLifetimeScope();
            builder.RegisterType <RewardPointService>().As <IRewardPointService>().InstancePerLifetimeScope();
            //builder.RegisterType<ShoppingCartService>().As<IShoppingCartService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomNumberFormatter>().As <ICustomNumberFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <PaymentService>().As <IPaymentService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CookieAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UrlRecordService>().As <IUrlRecordService>().InstancePerLifetimeScope();
            builder.RegisterType <ShipmentService>().As <IShipmentService>().InstancePerLifetimeScope();
            //  builder.RegisterType<ShippingService>().As<IShippingService>().InstancePerLifetimeScope();
            builder.RegisterType <DateRangeService>().As <IDateRangeService>().InstancePerLifetimeScope();
            builder.RegisterType <TaxCategoryService>().As <ITaxCategoryService>().InstancePerLifetimeScope();
            builder.RegisterType <TaxService>().As <ITaxService>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerActivityService>().As <ICustomerActivityService>().InstancePerLifetimeScope();
            builder.RegisterType <ForumService>().As <IForumService>().InstancePerLifetimeScope();
            builder.RegisterType <PollService>().As <IPollService>().InstancePerLifetimeScope();
            builder.RegisterType <BlogService>().As <IBlogService>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetService>().As <IWidgetService>().InstancePerLifetimeScope();
            builder.RegisterType <TopicService>().As <ITopicService>().InstancePerLifetimeScope();
            builder.RegisterType <NewsService>().As <INewsService>().InstancePerLifetimeScope();
            builder.RegisterType <DateTimeHelper>().As <IDateTimeHelper>().InstancePerLifetimeScope();
            builder.RegisterType <SitemapGenerator>().As <ISitemapGenerator>().InstancePerLifetimeScope();
            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();
            builder.RegisterType <ExportManager>().As <IExportManager>().InstancePerLifetimeScope();
            builder.RegisterType <ImportManager>().As <IImportManager>().InstancePerLifetimeScope();
            builder.RegisterType <PdfService>().As <IPdfService>().InstancePerLifetimeScope();
            builder.RegisterType <UploadService>().As <IUploadService>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeProvider>().As <IThemeProvider>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeContext>().As <IThemeContext>().InstancePerLifetimeScope();
            builder.RegisterType <ExternalAuthenticationService>().As <IExternalAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();


            builder.RegisterType <ActionContextAccessor>().As <IActionContextAccessor>().InstancePerLifetimeScope();

            //register all settings
            builder.RegisterSource(new SettingsSource());

            //picture service
            if (!string.IsNullOrEmpty(config.AzureBlobStorageConnectionString))
            {
                builder.RegisterType <AzurePictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }

            //installation service
            if (config.UseFastInstallationService)
            {
                builder.RegisterType <SqlFileInstallationService>().As <IInstallationService>().InstancePerLifetimeScope();
            }
            //else
            //builder.RegisterType<CodeFirstInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();

            //event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }

            builder.RegisterType <EventNotifyService>().As <IEventNotifyService>().InstancePerLifetimeScope();

            builder.Register <EventLogDao>(c => new EventLogDao(ConfigSetting.DataConnectionString)).SingleInstance();

            builder.RegisterType <EventBusRabbitMq>().As <IEventBus>().InstancePerLifetimeScope();

            var factory = new ConnectionFactory()
            {
                HostName = "192.168.1.251",
                UserName = "******",
                Password = "******",
            };

            builder.Register <IRabbitMqPersistentConnection>(c => new DefaultRabbitMqPersistentConnection(factory)).SingleInstance();
        }
示例#31
0
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             //register FakeHttpContext when HttpContext is not available
                             HttpContext.Current != null ?
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
                             (new FakeHttpContext("~/") as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();

            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();


            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();


            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new AppObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new AppObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            //Web Api
            //builder.RegisterType<ApplicationDbContext>().InstancePerHttpRequest();
            //builder.RegisterType<UserStore<ApplicationUser>>().As<IUserStore<ApplicationUser>>();
            //builder.RegisterType<UserManager<ApplicationUser>>();

            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            //cache manager
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("UHack_cache_static").SingleInstance();
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("UHack_cache_per_request").InstancePerLifetimeScope();

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();
            //application context
            builder.RegisterType <WebApplicationContext>().As <IApplicationContext>().InstancePerLifetimeScope();

            //services
            builder.RegisterType <CommonService>().As <ICommonService>().InstancePerLifetimeScope();



            builder.RegisterType <ApplicationService>().As <IApplicationService>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();
            builder.RegisterType <UrlRecordService>().As <IUrlRecordService>().InstancePerLifetimeScope();

            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();


            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();

            //pass MemoryCacheManager as cacheManager (cache settings between requests)
            builder.RegisterType <SettingService>().As <ISettingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("UHack_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());

            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();

            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();

            //Register event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
        }
示例#32
0
        /// <summary>
        ///     Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             //register FakeHttpContext when HttpContext is not available
                             HttpContext.Current != null
                    ? (new HttpContextWrapper(HttpContext.Current) as HttpContextBase)
                    : (new FakeHttpContext("~/") as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerLifetimeScope();

            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();
            //user agent helper
            builder.RegisterType <UserAgentHelper>().As <IUserAgentHelper>().InstancePerLifetimeScope();


            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>()))
            .As <BaseDataProviderManager>()
            .InstancePerDependency();


            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider())
            .As <IDataProvider>()
            .InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString))
                .InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(
                    c => new NopObjectContext(dataSettingsManager.LoadSettings().DataConnectionString))
                .InstancePerLifetimeScope();
            }


            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

            //plugins
            builder.RegisterType <PluginFinder>().As <IPluginFinder>().InstancePerLifetimeScope();
            builder.RegisterType <OfficialFeedManager>().As <IOfficialFeedManager>().InstancePerLifetimeScope();

            //cache managers
            if (config.RedisCachingEnabled)
            {
                //builder.RegisterType<RedisCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_static").InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>()
                .As <ICacheManager>()
                .Named <ICacheManager>("nop_cache_static")
                .SingleInstance();
            }
            builder.RegisterType <PerRequestCacheManager>()
            .As <ICacheManager>()
            .Named <ICacheManager>("nop_cache_per_request")
            .InstancePerLifetimeScope();

            if (config.RunOnAzureWebsites)
            {
                builder.RegisterType <AzureWebsitesMachineNameProvider>().As <IMachineNameProvider>().SingleInstance();
            }
            else
            {
                builder.RegisterType <DefaultMachineNameProvider>().As <IMachineNameProvider>().SingleInstance();
            }

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();

            //services
            builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerLifetimeScope();
            builder.RegisterType <PostService>().As <IPostService>().InstancePerLifetimeScope();
            builder.RegisterType <PostTagService>().As <IPostTagService>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryTemplateService>().As <ICategoryTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <PostTemplateService>().As <IPostTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryTypeService>().As <ICategoryTypeService>().InstancePerLifetimeScope();
            builder.RegisterType <TopicService>().As <ITopicService>().InstancePerLifetimeScope();
            builder.RegisterType <TopicTemplateService>().As <ITopicTemplateService>().InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <SearchTermService>().As <ISearchTermService>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <FulltextService>().As <IFulltextService>().InstancePerLifetimeScope();
            builder.RegisterType <MaintenanceService>().As <IMaintenanceService>().InstancePerLifetimeScope();


            builder.RegisterType <CustomerAttributeParser>().As <ICustomerAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeService>().As <ICustomerAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRegistrationService>()
            .As <ICustomerRegistrationService>()
            .InstancePerLifetimeScope();
            builder.RegisterType <CustomerReportService>().As <ICustomerReportService>().InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <PermissionService>().As <IPermissionService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            //use static cache (between HTTP requests)
            builder.RegisterType <AclService>().As <IAclService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            builder.RegisterType <GeoLookupService>().As <IGeoLookupService>().InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <SettingService>().As <ISettingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());

            //use static cache (between HTTP requests)
            builder.RegisterType <LocalizationService>().As <ILocalizationService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();

            //picture service
            builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();

            builder.RegisterType <MessageTemplateService>().As <IMessageTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailService>().As <IQueuedEmailService>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountService>().As <IEmailAccountService>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTokenProvider>().As <IMessageTokenProvider>().InstancePerLifetimeScope();
            builder.RegisterType <Tokenizer>().As <ITokenizer>().InstancePerLifetimeScope();
            builder.RegisterType <EmailSender>().As <IEmailSender>().InstancePerLifetimeScope();
            builder.RegisterType <WorkflowMessageService>().As <IWorkflowMessageService>().InstancePerLifetimeScope();
            builder.RegisterType <NewsLetterSubscriptionService>()
            .As <INewsLetterSubscriptionService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();


            //use static cache (between HTTP requests)
            builder.RegisterType <UrlRecordService>().As <IUrlRecordService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();


            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <CustomerActivityService>().As <ICustomerActivityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            //bool databaseInstalled = DataSettingsHelper.DatabaseIsInstalled();
            //if (!databaseInstalled)
            //{
            //    //installation service
            //    if (config.UseFastInstallationService)
            //    {
            //        builder.RegisterType<SqlFileInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
            //    }
            //    else
            //    {
            //        builder.RegisterType<CodeFirstInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
            //    }
            //}

            builder.RegisterType <PollService>().As <IPollService>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetService>().As <IWidgetService>().InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <WidgetService>().As <IWidgetService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            builder.RegisterType <DateTimeHelper>().As <IDateTimeHelper>().InstancePerLifetimeScope();
            builder.RegisterType <SitemapGenerator>().As <ISitemapGenerator>().InstancePerLifetimeScope();
            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope();

            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();

            builder.RegisterType <ExportManager>().As <IExportManager>().InstancePerLifetimeScope();
            builder.RegisterType <ImportManager>().As <IImportManager>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeProvider>().As <IThemeProvider>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeContext>().As <IThemeContext>().InstancePerLifetimeScope();


            builder.RegisterType <ExternalAuthorizer>().As <IExternalAuthorizer>().InstancePerLifetimeScope();
            builder.RegisterType <OpenAuthenticationService>()
            .As <IOpenAuthenticationService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ExternalAuthorizer>().As <IExternalAuthorizer>().InstancePerLifetimeScope();
            builder.RegisterType <OpenAuthenticationService>()
            .As <IOpenAuthenticationService>()
            .InstancePerLifetimeScope();


            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();

            //Register event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType &&
                                  ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
        }
示例#33
0
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                //register FakeHttpContext when HttpContext is not available
                //HttpContext.Current != null ?
                (new HttpContextWrapper(HttpContext.Current) as HttpContextBase)
                //(new FakeHttpContext("~/") as HttpContextBase)
                )
                .As<HttpContextBase>()
                .InstancePerRequest();
            builder.Register(c => c.Resolve<HttpContextBase>().Request)
                .As<HttpRequestBase>()
                .InstancePerRequest();
            builder.Register(c => c.Resolve<HttpContextBase>().Response)
                .As<HttpResponseBase>()
                .InstancePerRequest();
            builder.Register(c => c.Resolve<HttpContextBase>().Server)
                .As<HttpServerUtilityBase>()
                .InstancePerRequest();
            builder.Register(c => c.Resolve<HttpContextBase>().Session)
                .As<HttpSessionStateBase>()
                .InstancePerRequest();

            //web helper
            //builder.RegisterType<WebHelper>().As<IWebHelper>().InstancePerRequest();

            var assemblies = typeFinder.GetAssemblies().ToArray();

            //controllers
            builder.RegisterControllers(assemblies);
            //ApiControllers
            builder.RegisterApiControllers(assemblies);

            //View
            //builder.RegisterSource(new ViewRegistrationSource());

            //data layer
            var dataSettingsManager = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();
            builder.Register(c => dataSettingsManager.LoadSettings()).As<DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve<DataSettings>())).As<BaseDataProviderManager>().InstancePerDependency();


            builder.Register(x => x.Resolve<BaseDataProviderManager>().LoadDataProvider()).As<IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider = efDataProviderManager.LoadDataProvider();
                //dataProvider.InitConnectionFactory();
                ((SqlServerDataProvider)dataProvider).InitDatabase();

                builder.Register<IDbContext>(c => new EfDbContext(dataProviderSettings.DataConnectionString)).InstancePerRequest();
            }
            else
            {
                builder.Register<IDbContext>(c => new EfDbContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerRequest();
            }


            builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).InstancePerRequest();

            builder.RegisterAssemblyTypes(assemblies)
                .Where(t => typeof (IDependency).IsAssignableFrom(t) && t != typeof (IDependency))
                .AsImplementedInterfaces()
                .InstancePerRequest();
            builder.RegisterAssemblyTypes(assemblies)
                .Where(t => typeof (ISingletonDependency).IsAssignableFrom(t) && t != typeof (ISingletonDependency))
                .AsImplementedInterfaces()
                .SingleInstance();

            //IWorkContext
            builder.RegisterType<WorkContext>().As<IWorkContext>().InstancePerRequest();

            //filter
            //builder.RegisterFilterProvider(); //todo:使用YpDependencyResolver时此方法会报空
            builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);
            
            //注册YpHnadleError
            //全局注册
            builder.RegisterType<YpHandleErrorAttribute>().AsExceptionFilterFor<Controller>().SingleInstance();
            builder.RegisterType<YpAPIHandleErrorAttribute>().AsWebApiExceptionFilterFor<ApiController>().SingleInstance();
            //单个注册
            //builder.RegisterType<YpHandleErrorAttribute>().SingleInstance();
            //builder.RegisterType<YpAPIHandleErrorAttribute>().SingleInstance();

            //注册YpAuthorizeAttribute
            //全局注册
            builder.RegisterType<YpAPIAuthorizeAttribute>()
                .AsWebApiAuthorizationFilterFor<ApiController>()
                .PropertiesAutowired()
                .InstancePerRequest();
            builder.RegisterType<YpAuthorizeAttribute>()
                .AsAuthorizationFilterFor<Controller>()
                .PropertiesAutowired()
                .InstancePerRequest();
            //单个注册
            //builder.RegisterType<YpAPIAuthorizeAttribute>().PropertiesAutowired().InstancePerRequest();
            //builder.RegisterType<YpAuthorizeAttribute>().PropertiesAutowired().InstancePerRequest();
        }