public void Register(Autofac.ContainerBuilder builder, ITypeFinder typeFinder)
        {
            builder.RegisterType<WorkflowEngine>().As<IWorkflowEngine>().InstancePerHttpRequest();
            builder.RegisterAssemblyTypes(typeFinder.GetAssemblies().ToArray())
               .AssignableTo<IAutoActivityHandler>()
               .AsImplementedInterfaces();

            Assembly[] assemblies = typeFinder.GetAssemblies().ToArray();
            builder.RegisterAssemblyTypes(assemblies)
               .AssignableTo<IAutoActivityHandler>()
               .AsImplementedInterfaces();

            //regisger  [UUID("ApplyQuota-2.0-Approve-ActivityExecutedEvent")]
            var handlers = typeFinder.FindClassesOfType(typeof(IAutoActivityHandler)).ToList();
            foreach (var handler in handlers)
            {
                object[] attrs = handler.GetCustomAttributes(typeof(UUIDAttribute), false);
                string uuid = string.Empty;
                if (attrs != null)
                {
                    foreach (UUIDAttribute attr in attrs)
                    {
                        uuid = attr.UUID;
                    }
                    builder.RegisterType(handler).As<IAutoActivityHandler>().Keyed<IAutoActivityHandler>(uuid)
                    .InstancePerHttpRequest();
                }
            }

            //regisger  [UUID("ApplyQuota-2.0-Approve-ActivityExecutedEvent")]
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer<>)).ToList();
            foreach (var consumer in consumers)
            {
                object[] attrs = consumer.GetCustomAttributes(typeof(UUIDAttribute), false);
                string uuid = string.Empty;
                if (attrs != null)
                {
                    foreach (UUIDAttribute attr in attrs)
                    {
                        uuid = attr.UUID;
                    }
                    var interfaceType = consumer.FindInterfaces((type, criteria) =>
                    {
                        var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                        return isMatch;
                    }, typeof(IConsumer<>))[0];
                    builder.RegisterType(consumer).As(interfaceType)
                    .Keyed(uuid, interfaceType)
                    .InstancePerHttpRequest();
                }
            }
        }
    public 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();

        builder.RegisterType<SqlServerProvider>().As<IDbProvider>();

        builder.RegisterType<MemoryProvider>().Named<ICache>("memory");

         var list = typeFinder.FindClassesOfType<ICache>().ToList();
        list.ForEach(s=>builder.RegisterType(s));
        //list.ForEach(s=>builder.RegisterType<s>());
    }
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            Singleton<IDependencyResolver>.Instance = new DependencyResolver();

            string collectionString = "Data Source=.;Initial Catalog=demo;User ID=sa;Password=sa;Trusted_Connection=False;";
            builder.Register<IDbContext>(c => new WaterMoonContext(collectionString)).PerLifeStyle(ComponentLifeStyle.LifetimeScope);
            builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).PerLifeStyle(ComponentLifeStyle.LifetimeScope);
            builder.RegisterGeneric(typeof(PagedList<>)).As(typeof(IPagedList<>)).PerLifeStyle(ComponentLifeStyle.LifetimeScope);

            builder.RegisterType<DefualtMapping>().As<IMapping>().SingleInstance();

            //注册所有实现IConsumer<>类型的对象
            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<>)))
                    .PerLifeStyle(ComponentLifeStyle.LifetimeScope);
            }
            builder.RegisterType<EventPublisher>().As<IEventPublisher>().SingleInstance();
            builder.RegisterType<SubscriptionService>().As<ISubscriptionService>().SingleInstance();

            builder.RegisterType<DemoService>().As<IDemoService>().PerLifeStyle(ComponentLifeStyle.LifetimeScope);
        }
 public void RegisterDependencies(ContainerBuilder builder, ITypeFinder typeFinder)
 {
     var consumers = typeFinder.FindClassesOfType<IExamineEventsConsumer>(true);
     foreach (var consumer in consumers)
     {
         builder.RegisterType(consumer).As<IExamineEventsConsumer>().SingleInstance();
     }
 }
Beispiel #5
0
 public void RegisterDependencies(ContainerBuilder builder, ITypeFinder typeFinder)
 {
     var types = typeof(IConsumer<>);
     var consumers = typeFinder.FindClassesOfType(types);
     foreach (var consumer in consumers)
     {
         builder.RegisterType(consumer)
             .As(consumer.FindInterfaces((type, criteria) =>
                 type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition())
                 , typeof(IConsumer<>)))
             .InstancePerRequest();
     }
 }
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            var contextList = typeFinder.FindClassesOfType<BaseDbContext>(true);
            foreach (var type in contextList)
            {
                var dbname = type.Name.Replace("Entities","");
                if (ConfigurationManager.ConnectionStrings[dbname] == null)
                {
                    continue;

                }
                RegisterDB(builder, type, typeFinder);
            }

            //cache manager
            builder.RegisterType<CacheManager>().As<ICacheManager>().Named<ICacheManager>("sdf_cache_static").SingleInstance();

            var services = typeFinder.FindClassesOfType<BaseService>().ToList();
            services.ForEach(s => builder.RegisterType(s).AsImplementedInterfaces().PropertiesAutowired());

            builder.RegisterType<AccountService>().As<IAccount>();
        }
 /// <summary>
 /// Creates a factory instance and adds a http application injecting facility.
 /// </summary>
 /// <returns>A new factory</returns>
 public static IEngine CreateEngineInstance(ITypeFinder typeFinder)
 {
     var engines = typeFinder.FindClassesOfType<IEngine>().ToArray();
     engines = engines.Where(it => it != typeof(MEF.MEFEngine)).ToArray();
     if (engines.Length > 0)
     {
         var defaultEngine = (IEngine)Activator.CreateInstance(engines[0], typeFinder);
         return defaultEngine;
     }
     else
     {
         return new MEF.MEFEngine(typeFinder);
     }
 }
        private void RegisterDB(ContainerBuilder builder, Type type, ITypeFinder typeFinder)
        {
            var entityAssembly = Assembly.Load(type.Namespace);
            builder.RegisterType(type).Named<DbContext>(type.FullName);
            var a = new Assembly[] {entityAssembly};

            var typeList = typeFinder.FindClassesOfType<BaseEntity>(a,true);
            var tRepository = typeof(EfRepository<>);
            foreach (Type t in typeList)
            {
                var t2 = tRepository.MakeGenericType(t);
                builder.RegisterType(t2).AsImplementedInterfaces().WithParameter(ResolvedParameter.ForNamed<DbContext>(type.FullName));
            }
        }
Beispiel #9
0
        protected void MapGeneric(ContainerBuilder builder, ITypeFinder typeFinder, Type mapperType,
            IEnumerable<Type> contentTypes, Type defaultMapperType)
        {
            var allConverterTypes = typeFinder.FindClassesOfType(mapperType).ToArray();
            foreach (var contentType in contentTypes)
            {
                var specificMapperType = allConverterTypes.FirstOrDefault(ct =>
                {
                    var t = ct.GetInterfaces().First(i => i.IsGenericType && i.GetGenericTypeDefinition() == mapperType);
                    return t.GenericTypeArguments[0] == contentType;
                });

                var concreteType = specificMapperType ?? defaultMapperType.MakeGenericType(contentType);

                var target = mapperType.MakeGenericType(contentType);

                builder.RegisterType(concreteType).As(target).InstancePerRequest();
            }
        }
        public void Register(IServiceCollection services, IConfiguration configuration, ITypeFinder typeFinder, NopConfig nopConfig)
        {
            //file provider
            services.AddScoped <INopFileProvider, NopFileProvider>();

            //web helper
            services.AddScoped <IWebHelper, WebHelper>();

            //user agent helper
            services.AddScoped <IUserAgentHelper, UserAgentHelper>();

            //data layer
            services.AddTransient <IDataProviderManager, EfDataProviderManager>();
            //services.Register(context => context.Resolve<IDataProviderManager>().DataProvider).As<IDataProvider>().InstancePerDependency();
            services.AddTransient(provider => provider.GetRequiredService <IDataProviderManager>().DataProvider);
            services.AddScoped <IDbContext>(provider => new NopObjectContext(provider.GetRequiredService <DbContextOptions <NopObjectContext> >()));

            //repositories
            services.AddTransient(typeof(IRepository <>), typeof(EfRepository <>));

            //plugins
            services.AddScoped <IPluginFinder, PluginFinder>();
            services.AddScoped <IOfficialFeedManager, OfficialFeedManager>();

            //cache manager
            //services.AddScoped<ICacheManager, PerRequestCacheManager>();
            //services.AddScoped<ICacheManager, MemoryCacheManager>();
            services.AddScoped <ICacheManager, NopNullCache>();

            //static cache manager
            if (nopConfig.RedisCachingEnabled)
            {
                services.AddSingleton <ILocker, RedisConnectionWrapper>();
                services.AddSingleton <IRedisConnectionWrapper, RedisConnectionWrapper>();
                services.AddScoped <IStaticCacheManager, RedisCacheManager>();
            }
            else
            {
                services.AddSingleton <ILocker, MemoryCacheManager>();
                services.AddSingleton <IStaticCacheManager, MemoryCacheManager>();

                // PROBLEM Choice of CacheManager implementation
                // ADDED because PerRequestCacheManager doesn't work properly. Blazor doesn't support classical requests and
                // PerRequestCacheManager causes many errors including DBContext's and Thread's ones.
                //services.AddSingleton<ICacheManager, MemoryCacheManager>();
            }

            //work context
            services.AddScoped <IWorkContext, WebWorkContext>();

            //store context
            services.AddScoped <IStoreContext, WebStoreContext>();

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

            #region added
            //TODO added
            services.AddScoped <IEndpointPublisher, EndpointPublisher>();
            services.AddScoped <IJSService, JSService>();
            services.AddScoped <IRecentlyViewedProductsComponentService, RecentlyViewedProductsComponentService>();
            services.AddScoped <ICompareProductsComponentService, CompareProductsComponentService>();
            services.AddScoped <AuthenticationStateProvider, ComponentAuthStateProvider>();
            #endregion

            services.AddScoped <IActionContextAccessor, ActionContextAccessor>();

            //register all settings
            //services.RegisterSource(new SettingsSource());
            var settings = typeFinder.FindClassesOfType(typeof(ISettings)).ToList();
            foreach (var setting in settings)
            {
                services.AddScoped(setting,
                                   provider => provider.GetRequiredService <ISettingService>().LoadSetting(setting, provider.GetRequiredService <IStoreContext>().CurrentStore.Id));
            }

            //services.AddSingleton<IActionResultExecutor<RedirectResult>, NopRedirectResultExecutor>();

            //picture service
            if (!string.IsNullOrEmpty(nopConfig.AzureBlobStorageConnectionString))
            {
                services.AddScoped <IPictureService, AzurePictureService>();
            }
            else
            {
                services.AddScoped <IPictureService, PictureService>();
            }

            //installation service
            if (!DataSettingsManager.DatabaseIsInstalled)
            {
                if (nopConfig.UseFastInstallationService)
                {
                    services.AddScoped <IInstallationService, SqlFileInstallationService>();
                }
                else
                {
                    services.AddScoped <IInstallationService, CodeFirstInstallationService>();
                }
            }

            //event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();
            foreach (var consumer in consumers)
            {
                var consumersInterfaces = consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>));

                foreach (var @interface in consumersInterfaces)
                {
                    services.AddScoped(@interface, consumer);
                }
            }
        }
        /// <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 <IDbConnection>(c => new SqlConnection(config.MsSqlConnectionString)).InstancePerLifetimeScope();
            //builder.Register<IWriteDbContext>(c => new WriteObjectContext(config.MsSqlWriteConnectionString)).InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(DapperRepository <>)).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 <DapperQueryFilterExecuter>().As <IDapperQueryFilterExecuter>().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 <UnitOfWorkDbConnectionProvider>().As <IDbConnectionProvider>().InstancePerLifetimeScope();
            builder.RegisterType <CallContextCurrentUnitOfWorkProvider>().As <IUnitOfWorkProvider>().InstancePerLifetimeScope();
            builder.RegisterType <DapperUnitOfWork>().As <IUnitOfWork>().InstancePerLifetimeScope();
            builder.RegisterType <UnitOfWorkManager>().As <IUnitOfWorkManager>().InstancePerLifetimeScope();
            builder.RegisterType <DbContextDapperTransactionStrategy>().As <IDapperTransactionStrategy>().InstancePerLifetimeScope();
            //builder.RegisterType<CallContextAmbientDataContext>().As<IAmbientDataContext>().SingleInstance();
            //builder.RegisterGeneric(typeof(DataContextAmbientScopeProvider<>)).As(typeof(IAmbientScopeProvider<>)).InstancePerLifetimeScope();

            //serivce

            builder.RegisterType <GenerateService>().As <IGenerateService>().InstancePerLifetimeScope().EnableClassInterceptors();

            builder.RegisterType <RedisCacheManager>().As <IRedis>().InstancePerLifetimeScope();
        }
Beispiel #12
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();
        }
Beispiel #13
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 => (IEfDataProvider)x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();
            builder.Register(x => (IEfDataProvider)x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IEfDataProvider>().InstancePerDependency();

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

                builder.Register <IDbContext>(c => new NasObjectContext(dataProviderSettings.DataConnectionString)).InstancePerHttpRequest();
            }
            else
            {
                builder.Register <IDbContext>(c => new NasObjectContext(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>("Nas_cache_static").SingleInstance();
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("Nas_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>("Nas_cache_static"))
            .InstancePerHttpRequest();

            builder.RegisterType <AffiliateService>().As <IAffiliateService>().InstancePerHttpRequest();
            builder.RegisterType <VendorService>().As <IVendorService>().InstancePerHttpRequest();
            builder.RegisterType <AddressService>().As <IAddressService>().InstancePerHttpRequest();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerHttpRequest();
            builder.RegisterType <FulltextService>().As <IFulltextService>().InstancePerHttpRequest();
            builder.RegisterType <MaintenanceService>().As <IMaintenanceService>().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>("Nas_cache_static"))
            .InstancePerHttpRequest();
            //pass MemoryCacheManager as cacheManager (cache settings between requests)
            builder.RegisterType <AclService>().As <IAclService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("Nas_cache_static"))
            .InstancePerHttpRequest();

            builder.RegisterType <GeoCountryLookup>().As <IGeoCountryLookup>().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>("Nas_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>("Nas_cache_static"))
            .InstancePerHttpRequest();
            builder.RegisterSource(new SettingsSource());

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

            //pass MemoryCacheManager as cacheManager (cache locales between requests)
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("Nas_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>("Nas_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();
        }
        /// <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();
            //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();
        }
        /// <summary>
        /// Register routes
        /// </summary>
        /// <param name="routes">Routes</param>
        public virtual void /*List<NameTemplateDefaults>*/ RegisterRoutes(IApplicationBuilder app)
        {
            var routeProviderTypes = typeFinder.FindClassesOfType <IRouteProvider>();
            var routeProviders     = new List <IRouteProvider>();

            foreach (var providerType in routeProviderTypes)
            {
                //tbh wont need plugins for now
                //Ignore not installed plugins
                //var plugin = FindPlugin(providerType);
                //if (plugin != null && !plugin.Installed)
                //    continue;

                var provider = Activator.CreateInstance(providerType) as IRouteProvider;
                routeProviders.Add(provider);
            }
            routeProviders = routeProviders.OrderByDescending(rp => rp.Priority).ToList();



            app.UseMvc(routeBuilder =>
            {
                //should be only 2 elements in collection for now
                foreach (var routeProvider in routeProviders)
                {
                    routeProvider.RegisterRoutes(routeBuilder);
                }
            });



            //2017_07_03 previous and working

            //var routesToBeRegistered = new List<NameTemplateDefaults>();
            //foreach (var routeProvider in routeProviders)
            //{
            //    routesToBeRegistered.Concat(routeProvider.CollectRoutes(/*app*/routesToBeRegistered));
            //    //collectedRoutes.AddRange(dqwqqw.CollectRoutes(/*app*/collectedRoutes));
            //}

            //this is default route
            //apparently it isnt needed, but can be left
            //routesToBeRegistered/*routes*/.Add(new NameTemplateDefaults(
            //    name: "default",
            //    template: "{Home}/{Index}/{id?}", //"{controller=Home}/{action=Index}/{id?}",
            //    defaults: new { controller = "Home", action = "Index" }
            //    ));

            ////2017_06_06
            ////ad default route
            //routesToBeRegistered.Add(new NameTemplateDefaults(
            //    "Default", // Route name
            //    "{controller}/{action}/{id?}", // URL with parameters
            //     new { controller = "Home", action = "Index" }
            //    ));

            //app.UseMvc(routes =>
            //{
            //    routes.MapRoute("areaRoute", "{area:exists}/{controller=Home}/{action=Index}/{id?}");
            //    foreach (var route in routesToBeRegistered)
            //    {
            //        routes.MapRoute(
            //            name: route.Name,
            //            template: route.Template,
            //            defaults: route.Defaults
            //            );
            //    }
            //});
        }
Beispiel #17
0
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, MotelConfig config)
        {
            builder.RegisterType <MotelFileProvider>().As <IMotelFileProvider>().InstancePerLifetimeScope();

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


            //data layer
            //data layer
            #region data layer
            builder.RegisterType <DataProviderManager>().As <IDataProviderManager>().InstancePerDependency();
            builder.Register(context => context.Resolve <IDataProviderManager>().DataProvider).As <IMotelDataProvider>().InstancePerDependency();
            builder.RegisterType <MigrationManager>().As <IMigrationManager>().InstancePerDependency();
            builder.RegisterType <DataProviderManager>().As <IDataProviderManager>().InstancePerDependency();
            #endregion

            //repositories
            #region repositories
            builder.RegisterGeneric(typeof(EntityRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            #endregion

            #region Meida
            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope();
            builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();

            #endregion

            #region Auth
            builder.RegisterType <TokenValidatorService>().As <ITokenValidatorService>().InstancePerLifetimeScope();
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <RolesUserServices>().As <IRolesUserServices>().InstancePerLifetimeScope();
            builder.RegisterType <CookieAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <AntiForgeryCookieService>().As <IAntiForgeryCookieService>().InstancePerLifetimeScope();
            #endregion

            #region Lester
            builder.RegisterType <LesterServices>().As <ILesterServices>().InstancePerLifetimeScope();
            builder.RegisterType <LesterRegistrationService>().As <ILesterRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <TokenStoreService>().As <ITokenStoreService>().InstancePerLifetimeScope();
            builder.RegisterType <TokenFactoryService>().As <ITokenFactoryService>().InstancePerLifetimeScope();
            #endregion

            #region Post
            builder.RegisterType <RentalPostService>().As <IRentalPostService>().InstancePerDependency();

            builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerDependency();
            builder.RegisterType <TerritoriesServices>().As <ITerritoriesServices>().InstancePerDependency();
            builder.RegisterType <UtilitiesRoomServices>().As <IUtilitiesRoomServices>().InstancePerDependency();
            #endregion


            #region Cache and event
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().InstancePerDependency();
            builder.RegisterType <CacheKeyService>().As <ICacheKeyService>().InstancePerLifetimeScope();
            if (config.RedisEnabled)
            {
                builder.RegisterType <RedisConnectionWrapper>()
                .As <ILocker>()
                .As <IRedisConnectionWrapper>()
                .SingleInstance();
            }
            builder.RegisterType <RedisCacheManager>().As <IStaticCacheManager>().InstancePerLifetimeScope();

            builder.Register(context => context.Resolve <IDataProviderManager>().DataProvider).As <IMotelDataProvider>().InstancePerDependency();
            if (config.RedisEnabled)
            {
                builder.RegisterType <RedisConnectionWrapper>()
                .As <ILocker>()
                .As <IRedisConnectionWrapper>()
                .SingleInstance();
            }
            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();
            }
            #endregion

            #region Common
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();
            builder.RegisterType <ActionContextAccessor>().As <IActionContextAccessor>().InstancePerLifetimeScope();
            builder.RegisterType <CacheKeyService>().As <ICacheKeyService>().InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());
            #endregion
        }
Beispiel #18
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();

            //work context
            builder.RegisterType <WebApiWorkContext>().As <IWorkContext>().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 NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new NopObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            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();

            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 <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();
        }
Beispiel #19
0
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="appSettings">App settings</param>
        public virtual void Register(IServiceCollection services, ITypeFinder typeFinder, AppSettings appSettings)
        {
            //file provider
            services.AddScoped <INopFileProvider, NopFileProvider>();

            //web helper
            services.AddScoped <IWebHelper, WebHelper>();

            //user agent helper
            services.AddScoped <IUserAgentHelper, UserAgentHelper>();

            //data layer
            services.AddTransient <IDataProviderManager, DataProviderManager>();
            services.AddTransient(serviceProvider =>
                                  serviceProvider.GetRequiredService <IDataProviderManager>().DataProvider);

            //repositories
            services.AddScoped(typeof(IRepository <>), typeof(EntityRepository <>));

            //plugins
            services.AddScoped <IPluginService, PluginService>();
            services.AddScoped <OfficialFeedManager>();

            //static cache manager
            if (appSettings.DistributedCacheConfig.Enabled)
            {
                services.AddScoped <ILocker, DistributedCacheManager>();
                services.AddScoped <IStaticCacheManager, DistributedCacheManager>();
            }
            else
            {
                services.AddSingleton <ILocker, MemoryCacheManager>();
                services.AddSingleton <IStaticCacheManager, MemoryCacheManager>();
            }

            //work context
            services.AddScoped <IWorkContext, WebWorkContext>();

            //store context
            services.AddScoped <IStoreContext, WebStoreContext>();

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

            //plugin managers
            services.AddScoped(typeof(IPluginManager <>), typeof(PluginManager <>));
            services.AddScoped <IAuthenticationPluginManager, AuthenticationPluginManager>();
            services.AddScoped <IMultiFactorAuthenticationPluginManager, MultiFactorAuthenticationPluginManager>();
            services.AddScoped <IWidgetPluginManager, WidgetPluginManager>();
            services.AddScoped <IExchangeRatePluginManager, ExchangeRatePluginManager>();
            services.AddScoped <IDiscountPluginManager, DiscountPluginManager>();
            services.AddScoped <IPaymentPluginManager, PaymentPluginManager>();
            services.AddScoped <IPickupPluginManager, PickupPluginManager>();
            services.AddScoped <IShippingPluginManager, ShippingPluginManager>();
            services.AddScoped <ITaxPluginManager, TaxPluginManager>();

            services.AddSingleton <IActionContextAccessor, ActionContextAccessor>();

            //register all settings
            var settings = typeFinder.FindClassesOfType(typeof(ISettings), false).ToList();

            foreach (var setting in settings)
            {
                services.AddScoped(setting, serviceProvider =>
                {
                    var storeId = DataSettingsManager.IsDatabaseInstalled()
                        ? serviceProvider.GetRequiredService <IStoreContext>().GetCurrentStore()?.Id ?? 0
                        : 0;

                    return(serviceProvider.GetRequiredService <ISettingService>().LoadSettingAsync(setting, storeId).Result);
                });
            }

            //picture service
            if (appSettings.AzureBlobConfig.Enabled)
            {
                services.AddScoped <IPictureService, AzurePictureService>();
            }
            else
            {
                services.AddScoped <IPictureService, PictureService>();
            }

            //roxy file manager service
            services.AddTransient <DatabaseRoxyFilemanService>();
            services.AddTransient <FileRoxyFilemanService>();

            services.AddScoped <IRoxyFilemanService>(serviceProvider =>
            {
                return(serviceProvider.GetRequiredService <IPictureService>().IsStoreInDbAsync().Result
                    ? serviceProvider.GetRequiredService <DatabaseRoxyFilemanService>()
                    : serviceProvider.GetRequiredService <FileRoxyFilemanService>());
            });

            //installation service
            if (!DataSettingsManager.IsDatabaseInstalled())
            {
                services.AddScoped <IInstallationService, InstallationService>();
            }

            //slug route transformer
            if (DataSettingsManager.IsDatabaseInstalled())
            {
                services.AddScoped <SlugRouteTransformer>();
            }

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

            foreach (var consumer in consumers)
            {
                foreach (var findInterface in consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                {
                    services.AddScoped(findInterface, consumer);
                }
            }
        }
Beispiel #20
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)
        {
            //file provider
            builder.RegisterType <NopFileProvider>().As <INopFileProvider>().InstancePerLifetimeScope();

            //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(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();
            }

            //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 <ILocker>()
                .As <IRedisConnectionWrapper>()
                .SingleInstance();
                builder.RegisterType <RedisCacheManager>().As <IStaticCacheManager>().InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>()
                .As <ILocker>()
                .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 <VendorAttributeFormatter>().As <IVendorAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <VendorAttributeParser>().As <IVendorAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <VendorAttributeService>().As <IVendorAttributeService>().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 (!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();
            }
        }
        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();

            //web api controllers
            builder.RegisterApiControllers(typeFinder.GetAssemblies().ToArray());
            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager = new DataSettingsManager();

            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();

            var config = Singleton <AFConfig> .Instance;

            builder.Register <IDbContext>(c => new AFObjectContext(config.AfDataConnetcion)).Named <IDbContext>("AfDataConnetcion").InstancePerLifetimeScope();
            builder.Register <IDbContext>(c => new AFObjectContext(config.DefalutConnetcion)).InstancePerLifetimeScope();


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

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

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


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

            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();

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

            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRegistrationService>().As <ICustomerRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <MessageServices>().As <IMessageServices>().InstancePerLifetimeScope();
            builder.RegisterType <KnowledgeService>().As <IKnowledgeService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();
            builder.RegisterType <QuestionService>().As <IQuestionService>().InstancePerLifetimeScope();
            builder.RegisterType <SubjectService>().As <ISubjectService>().InstancePerLifetimeScope();
            builder.RegisterType <TiMuService>().As <ITiMuService>().InstancePerLifetimeScope();
            builder.RegisterType <BookWorkTaskService>().As <IBookWorkTaskService>().InstancePerLifetimeScope();
            builder.RegisterType <BookChapterService>().As <IBookChapterService>().InstancePerLifetimeScope();
            builder.RegisterType <BookService>().As <IBookService>().InstancePerLifetimeScope();
            builder.RegisterType <BookWorkTaskItemService>().As <IBookWorkTaskItemService>().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();
        }
        public IList <ITimelineWidget> GetTimelineWidgetsAcrossApp()
        {
            var types = _typeFinder.FindClassesOfType <ITimelineWidget>();

            return(types.Select(t => (ITimelineWidget)Activator.CreateInstance(t)).ToList());
        }
        /// <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, ResearchConfig config)
        {
            //file provider
            builder.RegisterType <ResearchFileProvider>().As <IResearchFileProvider>().InstancePerLifetimeScope();

            builder.RegisterType <CommonSettings>().As <ISettings>().InstancePerLifetimeScope();

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

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

            //data layer
            builder.RegisterType <EfDataProviderManager>().As <IDataProviderManager>().InstancePerDependency();
            builder.Register(context => context.Resolve <IDataProviderManager>().DataProvider).As <IDataProvider>().InstancePerDependency();
            builder.Register(context => new ProjectdbContext(context.Resolve <DbContextOptions <ProjectdbContext> >()))
            .As <IDbContext>().InstancePerLifetimeScope();
            //repositories
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

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

            //static cache manager
            builder.RegisterType <MemoryCacheManager>()
            .As <ILocker>()
            .As <IStaticCacheManager>()
            .SingleInstance();

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

            //services

            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <TitleService>().As <ITitleService>().InstancePerLifetimeScope();
            builder.RegisterType <InstituteService>().As <IInstituteService>().InstancePerLifetimeScope();
            builder.RegisterType <AddressService>().As <IAddressService>().InstancePerLifetimeScope();
            builder.RegisterType <FiscalScheduleService>().As <IFiscalScheduleService>().InstancePerLifetimeScope();
            builder.RegisterType <AcademicRankService>().As <IAcademicRankService>().InstancePerLifetimeScope();
            builder.RegisterType <AgencyService>().As <IAgencyService>().InstancePerLifetimeScope();
            builder.RegisterType <EducationLevelService>().As <IEducationLevelService>().InstancePerLifetimeScope();
            builder.RegisterType <FacultyService>().As <IFacultyService>().InstancePerLifetimeScope();
            builder.RegisterType <StrategyGroupService>().As <IStrategyGroupService>().InstancePerLifetimeScope();
            builder.RegisterType <ProfessorService>().As <IProfessorService>().InstancePerLifetimeScope();
            builder.RegisterType <ResearchIssueService>().As <IResearchIssueService>().InstancePerLifetimeScope();
            builder.RegisterType <ProjectService>().As <IProjectService>().InstancePerLifetimeScope();
            builder.RegisterType <ResearcherService>().As <IResearcherService>().InstancePerLifetimeScope();
            builder.RegisterType <UserRegistrationService>().As <IUserRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <CountryService>().As <ICountryService>().InstancePerLifetimeScope();
            builder.RegisterType <ProvinceService>().As <IProvinceService>().InstancePerLifetimeScope();
            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTemplateService>().As <IMessageTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailService>().As <IQueuedEmailService>().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 <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CookieAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UserActivityService>().As <IUserActivityService>().InstancePerLifetimeScope();
            builder.RegisterType <DateTimeHelper>().As <IDateTimeHelper>().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 <PictureService>().As <IPictureService>().SingleInstance();
            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 <EmailSender>().As <IEmailSender>().InstancePerLifetimeScope();

            builder.RegisterType <QueuedMessagesSendTask>().As <IScheduleTask>().InstancePerLifetimeScope();

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

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

            //picture service
            builder.RegisterType <PictureService>().As <IPictureService>().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();
            }

            //factories
            builder.RegisterType <BaseAdminModelFactory>().As <IBaseAdminModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ProjectModelFactory>().As <IProjectModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <UserModelFactory>().As <IUserModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ActivityLogModelFactory>().As <IActivityLogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LogModelFactory>().As <ILogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ResearcherModelFactory>().As <IResearcherModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ProfessorModelFactory>().As <IProfessorModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ResearchIssueModelFactory>().As <IResearchIssueModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <FiscalScheduleModelFactory>().As <IFiscalScheduleModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTemplateModelFactory>().As <IMessageTemplateModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountModelFactory>().As <IEmailAccountModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskModelFactory>().As <IScheduleTaskModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <UserRoleModelFactory>().As <IUserRoleModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SecurityModelFactory>().As <ISecurityModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailModelFactory>().As <IQueuedEmailModelFactory>().InstancePerLifetimeScope();
        }
Beispiel #24
0
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, TSConfig 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 <WebYardımcısı>().As <IWebYardımcısı>().InstancePerLifetimeScope();
            //user agent helper
            builder.RegisterType <KullanıcıAracıYardımcısı>().As <IKullanıcıAracıYardımcısı>().InstancePerLifetimeScope();


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

            //data layer
            var dataSettingsManager  = new DataAyarlarıYönetici();
            var dataProviderSettings = dataSettingsManager.AyarlarıYükle();

            builder.Register(c => dataSettingsManager.AyarlarıYükle()).As <DataAyarları>();
            builder.Register(x => new EfDataSağlayıcıYöneticisi(x.Resolve <DataAyarları>())).As <TemelVeriSağlayıcıYöneticisi>().InstancePerDependency();


            builder.Register(x => x.Resolve <TemelVeriSağlayıcıYöneticisi>().DataSağlayıcıYükle()).As <IDataSağlayıcı>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.Geçerli())
            {
                var efDataProviderManager = new EfDataSağlayıcıYöneticisi(dataSettingsManager.AyarlarıYükle());
                var dataProvider          = efDataProviderManager.DataSağlayıcıYükle();
                dataProvider.BağlantıFabrikasıBaşlat();

                builder.Register <IDbContext>(c => new TSObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new TSObjectContext(dataSettingsManager.AyarlarıYükle().DataConnectionString)).InstancePerLifetimeScope();
            }
            builder.RegisterGeneric(typeof(EfDepo <>)).As(typeof(IDepo <>)).InstancePerLifetimeScope();

            //plugins
            builder.RegisterType <EklentiBulucu>().As <IEklentiBulucu>().InstancePerLifetimeScope();


            //cache managers
            if (config.RedisCachingEnabled)
            {
                builder.RegisterType <RedisConnectionWrapper>().As <IRedisConnectionWrapper>().SingleInstance();
                builder.RegisterType <RedisÖnbellekYönetici>().As <IÖnbellekYönetici>().Named <IÖnbellekYönetici>("ts_cache_static").InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <BellekÖnbellekYönetici>().As <IÖnbellekYönetici>().Named <IÖnbellekYönetici>("ts_cache_static").SingleInstance();
            }
            builder.RegisterType <İstekBaşınaÖnbellekYöneticisi>().As <IÖnbellekYönetici>().Named <IÖnbellekYönetici>("ts_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 <WebSiteContext>().As <ISiteContext>().InstancePerLifetimeScope();
            builder.RegisterType <GenelÖznitelikServisi>().As <IGenelÖznitelikServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KullanıcıServisi>().As <IKullanıcıServisi>().InstancePerLifetimeScope();
            builder.RegisterType <SiteServisi>().As <ISiteServisi>().InstancePerLifetimeScope();

            //use static cache (between HTTP requests)
            builder.RegisterType <AyarlarServisi>().As <IAyarlarServisi>()
            .WithParameter(ResolvedParameter.ForNamed <IÖnbellekYönetici>("ts_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());
            builder.RegisterType <ResimServisi>().As <IResimServisi>().InstancePerLifetimeScope();

            builder.RegisterType <VarsayılanLogger>().As <ILogger>().InstancePerLifetimeScope();

            //use static cache (between HTTP requests)

            builder.RegisterType <WidgetServisi>().As <IWidgetServisi>().InstancePerLifetimeScope();
            builder.RegisterType <SayfaHeadOluşturucu>().As <ISayfaHeadOluşturucu>().InstancePerLifetimeScope();
            builder.RegisterType <TemaSağlayıcı>().As <ITemaSağlayıcı>().InstancePerLifetimeScope();
            builder.RegisterType <TemaContext>().As <ITemaContext>().InstancePerLifetimeScope();
            builder.RegisterType <RotaYayınlayıcı>().As <IRotaYayınlayıcı>().SingleInstance();
            //builder.RegisterType<KullanıcıServisi>().As<IKullanıcıServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KullanıcıKayıtServisi>().As <IKullanıcıKayıtServisi>().InstancePerLifetimeScope();
            builder.RegisterType <FormKimlikDoğrulamaServisi>().As <IKimlikDoğrulamaServisi>().InstancePerLifetimeScope();
            builder.RegisterType <ŞifrelemeServisi>().As <IŞifrelemeServisi>().InstancePerLifetimeScope();
            //Register event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IMüşteri <>)).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(IMüşteri <>)))
                .InstancePerLifetimeScope();
            }
            builder.RegisterType <OlayYayınlayıcı>().As <IOlayYayınlayıcı>().SingleInstance();
            builder.RegisterType <AbonelikServisi>().As <IAbonelikServisi>().SingleInstance();
            builder.RegisterType <İzinServisi>().As <IİzinServisi>()
            .WithParameter(ResolvedParameter.ForNamed <IÖnbellekYönetici>("cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <KategoriServisi>().As <IKategoriServisi>().InstancePerLifetimeScope();
            builder.RegisterType <SayfalarServisi>().As <ISayfalarServisi>().InstancePerLifetimeScope();
            builder.RegisterType <BankalarServisi>().As <IBankalarServisi>().InstancePerLifetimeScope();
            builder.RegisterType <MusteriSektorServisi>().As <IMusteriSektorServisi>().InstancePerLifetimeScope();
            builder.RegisterType <TedarikciSektorServisi>().As <ITedarikciSektorServisi>().InstancePerLifetimeScope();
            builder.RegisterType <HariciSektorServisi>().As <IHariciSektorServisi>().InstancePerLifetimeScope();
            builder.RegisterType <TeklifKalemiServisi>().As <ITeklifKalemiServisi>().InstancePerLifetimeScope();
            builder.RegisterType <UnvanlarServisi>().As <IUnvanlarServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KonumServisi>().As <IKonumServisi>().InstancePerLifetimeScope();
            builder.RegisterType <TeklifServisi>().As <ITeklifServisi>().InstancePerLifetimeScope();
            builder.RegisterType <Teklif2Servisi>().As <ITeklif2Servisi>().InstancePerLifetimeScope();
            builder.RegisterType <BagliTeklifOgesiServisi>().As <IBagliTeklifOgesiServisi>().InstancePerLifetimeScope();
            builder.RegisterType <BagliTeklifOgesi2Servisi>().As <IBagliTeklifOgesi2Servisi>().InstancePerLifetimeScope();
            builder.RegisterType <TeklifHariciServisi>().As <ITeklifHariciServisi>().InstancePerLifetimeScope();
            builder.RegisterType <BagliTeklifOgesiHariciServisi>().As <IBagliTeklifOgesiHariciServisi>().InstancePerLifetimeScope();
            builder.RegisterType <GorusmeRaporlariServisi>().As <IGorusmeRaporlariServisi>().InstancePerLifetimeScope();
            builder.RegisterType <OdemeFormuServisi>().As <IOdemeFormuServisi>().InstancePerLifetimeScope();
            builder.RegisterType <HintServisi>().As <IHintServisi>().InstancePerLifetimeScope();
            builder.RegisterType <PdfServisi>().As <IPdfServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KatilimciServisi>().As <IKatilimciServisi>().InstancePerLifetimeScope();
            builder.RegisterType <RefakatciServisi>().As <IRefakatciServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KayitServisi>().As <IKayitServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KonaklamaServisi>().As <IKonaklamaServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KursServisi>().As <IKursServisi>().InstancePerLifetimeScope();
            builder.RegisterType <TransferServisi>().As <ITransferServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KongreServisi>().As <IKongreServisi>().InstancePerLifetimeScope();
            builder.RegisterType <NotServisi>().As <INotServisi>().InstancePerLifetimeScope();
            builder.RegisterType <DovizServisi>().As <IDovizServisi>().InstancePerLifetimeScope();
            builder.RegisterType <MesajServisi>().As <IMesajServisi>().InstancePerLifetimeScope();
            builder.RegisterType <MesajlarServisi>().As <IMesajlarServisi>().InstancePerLifetimeScope();
            builder.RegisterType <TestServisi>().As <ITestServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KontenjanServisi>().As <IKontenjanServisi>().InstancePerLifetimeScope();

            builder.RegisterType <CrmGorevServisi>().As <ICrmGorevServisi>().InstancePerLifetimeScope();
            builder.RegisterType <CrmUnvanServisi>().As <ICrmUnvanServisi>().InstancePerLifetimeScope();
            builder.RegisterType <CrmKisiServisi>().As <ICrmKisiServisi>().InstancePerLifetimeScope();
            builder.RegisterType <CrmKurumServisi>().As <ICrmKurumServisi>().InstancePerLifetimeScope();
            builder.RegisterType <CrmKongreServisi>().As <ICrmKongreServisi>().InstancePerLifetimeScope();
            builder.RegisterType <CrmGorusmeServisi>().As <ICrmGorusmeServisi>().InstancePerLifetimeScope();
            builder.RegisterType <CrmFirmaGorusmeServisi>().As <ICrmFirmaGorusmeServisi>().InstancePerLifetimeScope();
            builder.RegisterType <CrmYonetimKuruluServisi>().As <ICrmYonetimKuruluServisi>().InstancePerLifetimeScope();
            builder.RegisterType <CrmFirmaServisi>().As <ICrmFirmaServisi>().InstancePerLifetimeScope();
            builder.RegisterType <CrmFirmaYetkilisiServisi>().As <ICrmFirmaYetkilisiServisi>().InstancePerLifetimeScope();


            builder.RegisterType <BültenAbonelikServisi>().As <IBültenAbonelikServisi>().InstancePerLifetimeScope();
            builder.RegisterType <ÜlkeServisi>().As <IÜlkeServisi>().InstancePerLifetimeScope();
            builder.RegisterType <AçıkYetkilendirmeServisi>().As <IAçıkYetkilendirmeServisi>().InstancePerLifetimeScope();
            builder.RegisterType <TarihYardımcısı>().As <ITarihYardımcısı>().InstancePerLifetimeScope();
            builder.RegisterType <KullanıcıİşlemServisi>().As <IKullanıcıİşlemServisi>()
            .WithParameter(ResolvedParameter.ForNamed <IÖnbellekYönetici>("cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <MesajTemasıServisi>().As <IMesajTemasıServisi>().InstancePerLifetimeScope();
            builder.RegisterType <MesajServisi>().As <IMesajServisi>().InstancePerLifetimeScope();
            builder.RegisterType <EmailHesapServisi>().As <IEmailHesapServisi>().InstancePerLifetimeScope();
            builder.RegisterType <BekleyenMailServisi>().As <IBekleyenMailServisi>().InstancePerLifetimeScope();
            builder.RegisterType <ForumServisi>().As <IForumServisi>().InstancePerLifetimeScope();
            builder.RegisterType <UrlKayıtServisi>().As <IUrlKayıtServisi>()
            .WithParameter(ResolvedParameter.ForNamed <IÖnbellekYönetici>("cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <AclServisi>().As <IAclServisi>()
            .WithParameter(ResolvedParameter.ForNamed <IÖnbellekYönetici>("cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <SiteMappingServisi>().As <ISiteMappingServisi>()
            .WithParameter(ResolvedParameter.ForNamed <IÖnbellekYönetici>("cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <SayfaTemaServisi>().As <ISayfaTemaServisi>().InstancePerLifetimeScope();
            builder.RegisterType <HaberServisi>().As <IHaberServisi>().InstancePerLifetimeScope();
            builder.RegisterType <BlogServisi>().As <IBlogServisi>().InstancePerLifetimeScope();
            builder.RegisterType <AnketServisi>().As <IAnketServisi>().InstancePerLifetimeScope();
            builder.RegisterType <TamMetinServisi>().As <ITamMetinServisi>().InstancePerLifetimeScope();
            builder.RegisterType <EmailGönderici>().As <IEmailGönderici>().InstancePerLifetimeScope();
            builder.RegisterType <DownloadServisi>().As <IDownloadServisi>().InstancePerLifetimeScope();
            builder.RegisterType <XlsDosyaServisi>().As <IXlsDosyaServisi>().InstancePerLifetimeScope();
            builder.RegisterType <XlsServisi>().As <IXlsServisi>().InstancePerLifetimeScope();
            builder.RegisterType <XlsUploadServisi>().As <IXlsUploadServisi>().InstancePerLifetimeScope();
            builder.RegisterType <BankaBilgileriServisi>().As <IBankaBilgileriServisi>().InstancePerLifetimeScope();
            builder.RegisterType <GelirGiderHedefiServisi>().As <IGelirGiderHedefiServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KontenjanBilgileriServisi>().As <IKontenjanBilgileriServisi>().InstancePerLifetimeScope();
            builder.RegisterType <TakvimServisi>().As <ITakvimServisi>().InstancePerLifetimeScope();
            builder.RegisterType <GelirGiderTanımlamaServisi>().As <IGelirGiderTanımlamaServisi>().InstancePerLifetimeScope();
            builder.RegisterType <SponsorlukKalemleriServisi>().As <ISponsorlukKalemleriServisi>().InstancePerLifetimeScope();
            builder.RegisterType <HekimBranşlarıServisi>().As <IHekimBranşlarıServisi>().InstancePerLifetimeScope();
            builder.RegisterType <HekimlerServisi>().As <IHekimlerServisi>().InstancePerLifetimeScope();
            builder.RegisterType <TedarikciKategorileriServisi>().As <ITedarikciKategorileriServisi>().InstancePerLifetimeScope();
            builder.RegisterType <YetkililerServisi>().As <IYetkililerServisi>().InstancePerLifetimeScope();
            builder.RegisterType <FirmaServisi>().As <IFirmaServisi>().InstancePerLifetimeScope();
            builder.RegisterType <FirmaKategorisiServisi>().As <IFirmaKategorisiServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KongreTedarikçiServisi>().As <IKongreTedarikçiServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KongreGörüşmeRaporlarıServisi>().As <IKongreGörüşmeRaporlarıServisi>().InstancePerLifetimeScope();
            builder.RegisterType <SponsorlukSatışıServisi>().As <ISponsorlukSatışıServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KayıtTipiServisi>().As <IKayıtTipiServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KayıtBilgileriServisi>().As <IKayıtBilgileriServisi>().InstancePerLifetimeScope();
            builder.RegisterType <KursBilgileriServisi>().As <IKursBilgileriServisi>().InstancePerLifetimeScope();
            builder.RegisterType <GenelSponsorlukServisi>().As <IGenelSponsorlukServisi>().InstancePerLifetimeScope();
            builder.RegisterType <TransferServisi>().As <ITransferServisi>().InstancePerLifetimeScope();
        }
Beispiel #25
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)
        {
            //file provider
            builder.RegisterType <AppFileProvider>().As <IAppFileProvider>().InstancePerLifetimeScope();

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

            //data layer
            builder.Register(context => new AppObjectContext(context.Resolve <DbContextOptions <AppObjectContext> >()))
            .As <IDbContext>().InstancePerLifetimeScope();

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

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

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

            builder.RegisterType <MemoryCacheManager>()
            .As <ILocker>()
            .As <IStaticCacheManager>()
            .SingleInstance();

            //services
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <CookieAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UserRegistrationService>().As <IUserRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <NotificationService>().As <INotificationService>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerLifetimeScope();
            builder.RegisterType <QuestionService>().As <IQuestionService>().InstancePerLifetimeScope();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();
            builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope();

            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();

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

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

            //roxy file manager service
            builder.Register(context =>
            {
                var pictureService = context.Resolve <IPictureService>();

                return(EngineContext.Current.ResolveUnregistered(pictureService.StoreInDb
                    ? typeof(DatabaseRoxyFilemanService)
                    : typeof(FileRoxyFilemanService)));
            }).As <IRoxyFilemanService>().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();
            }
        }
Beispiel #26
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, GrandConfig config)
        {
            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();

            //powered by
            builder.RegisterType <PoweredByMiddlewareOptions>().As <IPoweredByMiddlewareOptions>().SingleInstance();

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

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

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var connectionString = dataProviderSettings.DataConnectionString;
                var databaseName     = new MongoUrl(connectionString).DatabaseName;
                builder.Register(c => new MongoClient(connectionString).GetDatabase(databaseName)).SingleInstance();
                builder.Register <IMongoDBContext>(c => new MongoDBContext(connectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MongoDBContext>().As <IMongoDBContext>().InstancePerLifetimeScope();
            }

            //MongoDbRepository
            builder.RegisterGeneric(typeof(MongoDBRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

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

            //cache manager
            builder.RegisterType <PerRequestCacheManager>().InstancePerLifetimeScope();
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().SingleInstance();
            if (config.RedisPubSubEnabled)
            {
                var redis = ConnectionMultiplexer.Connect(config.RedisPubSubConnectionString);
                builder.Register(c => redis.GetSubscriber()).As <ISubscriber>().SingleInstance();
                builder.RegisterType <RedisMessageBus>().As <IMessageBus>().SingleInstance();
                builder.RegisterType <RedisMessageCacheManager>().As <ICacheManager>().SingleInstance();
            }
            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();

            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizationService>().As <ILocalizationService>().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 <ProductReservationService>().As <IProductReservationService>().InstancePerLifetimeScope();
            builder.RegisterType <AuctionService>().As <IAuctionService>().InstancePerLifetimeScope();
            builder.RegisterType <ProductCourseService>().As <IProductCourseService>().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 <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 <CustomerTagService>().As <ICustomerTagService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerActionService>().As <ICustomerActionService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerActionEventService>().As <ICustomerActionEventService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReminderService>().As <ICustomerReminderService>().InstancePerLifetimeScope();
            builder.RegisterType <UserApiService>().As <IUserApiService>().InstancePerLifetimeScope();

            builder.RegisterType <RewardPointsService>().As <IRewardPointsService>().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 <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();
            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope();

            var provider = new FileExtensionContentTypeProvider();

            builder.RegisterType <MimeMappingService>().As <IMimeMappingService>()
            .WithParameter(new TypedParameter(typeof(FileExtensionContentTypeProvider), provider))
            .InstancePerLifetimeScope();

            //picture service
            var useAzureBlobStorage  = !String.IsNullOrEmpty(config.AzureBlobStorageConnectionString);
            var useAmazonBlobStorage = (!String.IsNullOrEmpty(config.AmazonAwsAccessKeyId) && !String.IsNullOrEmpty(config.AmazonAwsSecretAccessKey) && !String.IsNullOrEmpty(config.AmazonBucketName) && !String.IsNullOrEmpty(config.AmazonRegion));

            if (useAzureBlobStorage)
            {
                //Windows Azure BLOB
                builder.RegisterType <AzurePictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }
            else if (useAmazonBlobStorage)
            {
                //Amazon S3 Simple Storage Service
                builder.RegisterType <AmazonPictureService>().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 <NewsletterCategoryService>().As <INewsletterCategoryService>().InstancePerLifetimeScope();
            builder.RegisterType <CampaignService>().As <ICampaignService>().InstancePerLifetimeScope();
            builder.RegisterType <BannerService>().As <IBannerService>().InstancePerLifetimeScope();
            builder.RegisterType <PopupService>().As <IPopupService>().InstancePerLifetimeScope();
            builder.RegisterType <InteractiveFormService>().As <IInteractiveFormService>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountService>().As <IEmailAccountService>().InstancePerLifetimeScope();
            builder.RegisterType <WorkflowMessageService>().As <IWorkflowMessageService>().InstancePerLifetimeScope();
            builder.RegisterType <ContactAttributeFormatter>().As <IContactAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <ContactAttributeParser>().As <IContactAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <ContactAttributeService>().As <IContactAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTokenProvider>().As <IMessageTokenProvider>().InstancePerLifetimeScope();
            builder.RegisterType <Tokenizer>().As <ITokenizer>().InstancePerLifetimeScope();
            builder.RegisterType <EmailSender>().As <IEmailSender>().InstancePerLifetimeScope();
            builder.RegisterType <HistoryService>().As <IHistoryService>().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 <RewardPointsService>().As <IRewardPointsService>().InstancePerLifetimeScope();
            builder.RegisterType <ShoppingCartService>().As <IShoppingCartService>().InstancePerLifetimeScope();
            builder.RegisterType <PaymentService>().As <IPaymentService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CookieAuthenticationService>().As <IGrandAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <ApiAuthenticationService>().As <IApiAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UrlRecordService>().As <IUrlRecordService>().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();
            builder.RegisterType <ContactUsService>().As <IContactUsService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerActivityService>().As <ICustomerActivityService>().InstancePerLifetimeScope();
            builder.RegisterType <ActivityKeywordsProvider>().As <IActivityKeywordsProvider>().InstancePerLifetimeScope();

            bool databaseInstalled = DataSettingsHelper.DatabaseIsInstalled();

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

            builder.RegisterType <ForumService>().As <IForumService>().InstancePerLifetimeScope();
            builder.RegisterType <KnowledgebaseService>().As <IKnowledgebaseService>().InstancePerLifetimeScope();
            builder.RegisterType <PushNotificationsService>().As <IPushNotificationsService>().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 <ExternalAuthenticationService>().As <IExternalAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <GoogleAnalyticsService>().As <IGoogleAnalyticsService>().InstancePerLifetimeScope();
            builder.RegisterType <DocumentTypeService>().As <IDocumentTypeService>().InstancePerLifetimeScope();
            builder.RegisterType <DocumentService>().As <IDocumentService>().InstancePerLifetimeScope();

            builder.RegisterType <CourseActionService>().As <ICourseActionService>().InstancePerLifetimeScope();
            builder.RegisterType <CourseLessonService>().As <ICourseLessonService>().InstancePerLifetimeScope();
            builder.RegisterType <CourseLevelService>().As <ICourseLevelService>().InstancePerLifetimeScope();
            builder.RegisterType <CourseService>().As <ICourseService>().InstancePerLifetimeScope();
            builder.RegisterType <CourseSubjectService>().As <ICourseSubjectService>().InstancePerLifetimeScope();

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

            builder.RegisterType <SlugRouteTransformer>().InstancePerLifetimeScope();

            var validators = typeFinder.FindClassesOfType(typeof(IValidator)).ToList();

            foreach (var validator in validators)
            {
                builder.RegisterType(validator);
            }

            //validator consumers
            var validatorconsumers = typeFinder.FindClassesOfType(typeof(IValidatorConsumer <>)).ToList();

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

            builder.RegisterType <ResourceManager>().As <IResourceManager>().InstancePerLifetimeScope();

            //Register task
            builder.RegisterType <QueuedMessagesSendScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <ClearCacheScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <ClearLogScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReminderAbandonedCartScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReminderBirthdayScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReminderCompletedOrderScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReminderLastActivityScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReminderLastPurchaseScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReminderRegisteredCustomerScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReminderUnpaidOrderScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <DeleteGuestsScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <UpdateExchangeRateScheduleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
            builder.RegisterType <EndAuctionsTask>().As <IScheduleTask>().InstancePerLifetimeScope();
        }
Beispiel #27
0
        public 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 =>
                             //register FakeHttpContext when HttpContext is not available

                             (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();

            //PerHttpRequest

            //do not change the order of the registration because autofac will always resolve the one having the latest registration, by default it should resolve the default db.
            //builder.RegisterType<NewAimWebAPIClientDbContext>().As<IDbContext>().Keyed<IDbContext>(Constants.APIClientDBKey).InstancePerHttpRequest();
            //builder.RegisterType<NewAimWebDMDbContext>().As<IDbContext>().Keyed<IDbContext>(Constants.DeliveryManagementSystemDBKey).InstancePerHttpRequest();
            //builder.RegisterType<NewAimWebWMSDbContext>().As<IDbContext>().Keyed<IDbContext>(Constants.WMSDBKey).InstancePerHttpRequest();
            builder.RegisterType <DropshipDBContext>().As <IDbContext>().Keyed <IDbContext>(Constants.DropshipDBKey).InstancePerLifetimeScope();


            builder.RegisterGeneric(typeof(DropshipRepository <>)).As(typeof(IRepository <>)).WithParameter(
                new ResolvedParameter((pi, c) => pi.ParameterType == typeof(IDbContext), (pi, c) => c.ResolveKeyed <IDbContext>(SelectDB(pi.Member.DeclaringType.GetGenericArguments()[0])))).InstancePerLifetimeScope();


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

            //Sigleton
            builder.RegisterType <CacheManager>().As <ICacheManager>().SingleInstance();

            //Common
            builder.RegisterType <CommonService>().As <ICommonService>().InstancePerLifetimeScope();
            builder.RegisterType <PostageRuleService>().As <IPostageRuleService>().InstancePerLifetimeScope();

            //Item
            builder.RegisterType <ItemService>().As <IItemService>().InstancePerLifetimeScope();
            builder.RegisterType <ImageService>().As <IImageService>().InstancePerLifetimeScope();

            //Listing
            builder.RegisterType <ListingService>().As <IListingService>().InstancePerLifetimeScope();

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

            //Security
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();


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

            //eBay Service
            builder.RegisterType <eBayAPIContextProvider>().As <IeBayAPIContextProvider>().InstancePerLifetimeScope();
            builder.RegisterType <eBayAPICallManager>().As <IeBayAPICallManager>().InstancePerLifetimeScope();

            //Dropship Framework
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();

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

            //Import/Export Manager
            //builder.RegisterType<ExportManager>().As<IExportManager>().InstancePerLifetimeScope();

            //Event
            //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>
 /// Returns all types found of in the assemblies specified of type T
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="typeFinder"></param>
 /// <param name="assemblies"></param>
 /// <param name="onlyConcreteClasses"></param>
 /// <returns></returns>
 public static IEnumerable <Type> FindClassesOfType <T>(this ITypeFinder typeFinder, IEnumerable <Assembly> assemblies = null, bool onlyConcreteClasses = true)
 => typeFinder.FindClassesOfType(typeof(T), assemblies, onlyConcreteClasses);
        /// <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, BopConfig config)
        {
            //file provider
            builder.RegisterType <BopFileProvider>().As <IBopFileProvider>().InstancePerLifetimeScope();

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

            //data layer
            builder.RegisterType <DataProviderManager>().As <IDataProviderManager>().InstancePerDependency();
            builder.Register(context => context.Resolve <IDataProviderManager>().DataProvider).As <IBopDataProvider>().InstancePerDependency();

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


            //redis connection wrapper
            if (config.RedisEnabled)
            {
                builder.RegisterType <RedisConnectionWrapper>()
                .As <ILocker>()
                .As <IRedisConnectionWrapper>()
                .SingleInstance();
            }

            //static cache manager
            if (config.RedisEnabled && config.UseRedisForCaching)
            {
                builder.RegisterType <RedisCacheManager>().As <IStaticCacheManager>().InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>()
                .As <ILocker>()
                .As <IStaticCacheManager>()
                .SingleInstance();
            }

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

            //store context
            builder.RegisterType <HostedSiteContext>().As <IHostedSiteContext>().InstancePerLifetimeScope();


            //services
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizationService>().As <ILocalizationService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <JwtAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();
            builder.RegisterType <HostedSiteService>().As <IHostedSiteService>().InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRegistrationService>().As <ICustomerRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <WorkflowMessageService>().As <IWorkflowMessageService>().InstancePerLifetimeScope();
            builder.RegisterType <TokenStoreService>().As <ITokenStoreService>().InstancePerLifetimeScope();
            builder.RegisterType <TokenValidatorService>().As <ITokenValidatorService>().InstancePerLifetimeScope();
            builder.RegisterType <TokenFactoryService>().As <ITokenFactoryService>().InstancePerLifetimeScope();
            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
            builder.RegisterType <CacheKeyService>().As <ICacheKeyService>().InstancePerLifetimeScope();

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

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

            //installation service
            if (!DataSettingsManager.DatabaseIsInstalled)
            {
                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();
            }
        }
Beispiel #30
0
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="appSettings">App settings</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, AppSettings appSettings)
        {
            //file provider
            builder.RegisterType <NopFileProvider>().As <INopFileProvider>().InstancePerLifetimeScope();

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

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

            //data layer
            builder.RegisterType <DataProviderManager>().As <IDataProviderManager>().InstancePerDependency();
            builder.Register(context => context.Resolve <IDataProviderManager>().DataProvider).As <INopDataProvider>().InstancePerDependency();

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

            //plugins
            builder.RegisterType <PluginService>().As <IPluginService>().InstancePerLifetimeScope();
            builder.RegisterType <OfficialFeedManager>().AsSelf().InstancePerLifetimeScope();

            //redis connection wrapper
            if (appSettings.RedisConfig.Enabled)
            {
                builder.RegisterType <RedisConnectionWrapper>()
                .As <ILocker>()
                .As <IRedisConnectionWrapper>()
                .SingleInstance();
            }

            //static cache manager
            if (appSettings.RedisConfig.Enabled && appSettings.RedisConfig.UseCaching)
            {
                builder.RegisterType <RedisCacheManager>().As <IStaticCacheManager>().InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>()
                .As <ILocker>()
                .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 <VendorAttributeFormatter>().As <IVendorAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <VendorAttributeParser>().As <IVendorAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <VendorAttributeService>().As <IVendorAttributeService>().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 <NotificationService>().As <INotificationService>().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 <SmtpBuilder>().As <ISmtpBuilder>().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 <GdprService>().As <IGdprService>().InstancePerLifetimeScope();
            builder.RegisterType <PollService>().As <IPollService>().InstancePerLifetimeScope();
            builder.RegisterType <BlogService>().As <IBlogService>().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();
            //slug route transformer
            builder.RegisterType <SlugRouteTransformer>().AsSelf().InstancePerLifetimeScope();
            builder.RegisterType <ReviewTypeService>().As <IReviewTypeService>().SingleInstance();
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();

            //plugin managers
            builder.RegisterGeneric(typeof(PluginManager <>)).As(typeof(IPluginManager <>)).InstancePerLifetimeScope();
            builder.RegisterType <AuthenticationPluginManager>().As <IAuthenticationPluginManager>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetPluginManager>().As <IWidgetPluginManager>().InstancePerLifetimeScope();
            builder.RegisterType <ExchangeRatePluginManager>().As <IExchangeRatePluginManager>().InstancePerLifetimeScope();
            builder.RegisterType <DiscountPluginManager>().As <IDiscountPluginManager>().InstancePerLifetimeScope();
            builder.RegisterType <PaymentPluginManager>().As <IPaymentPluginManager>().InstancePerLifetimeScope();
            builder.RegisterType <PickupPluginManager>().As <IPickupPluginManager>().InstancePerLifetimeScope();
            builder.RegisterType <ShippingPluginManager>().As <IShippingPluginManager>().InstancePerLifetimeScope();
            builder.RegisterType <TaxPluginManager>().As <ITaxPluginManager>().InstancePerLifetimeScope();

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

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

            //picture service
            if (appSettings.AzureBlobConfig.Enabled)
            {
                builder.RegisterType <AzurePictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }

            //roxy file manager service
            builder.Register(context =>
            {
                var pictureService = context.Resolve <IPictureService>();

                return(EngineContext.Current.ResolveUnregistered(pictureService.StoreInDb
                    ? typeof(DatabaseRoxyFilemanService)
                    : typeof(FileRoxyFilemanService)));
            }).As <IRoxyFilemanService>().InstancePerLifetimeScope();

            //installation service
            if (!DataSettingsManager.DatabaseIsInstalled)
            {
                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();
            }
        }
Beispiel #31
0
 public static IEnumerable <Type> FindClassesOfType(this ITypeFinder finder, Type assignTypeFrom, bool onlyConcreteClasses = true)
 {
     return(finder.FindClassesOfType(assignTypeFrom, finder.GetAssemblies(), onlyConcreteClasses));
 }
        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
            var assemblies = typeFinder.GetAssemblies().ToArray();

            builder.RegisterApiControllers(assemblies);

            //data layer
            builder.RegisterType <SqlServerDataProvider>().As <IDataProvider>().InstancePerLifetimeScope();
            builder.Register <IDbContext>(c => new PanoramaQuzhouObjectContext()).AsSelf().InstancePerLifetimeScope();//.InstancePerLifetimeScope();
            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 <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("qm_cache_static").SingleInstance();
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("qm_cache_per_request").InstancePerLifetimeScope();


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

            #region 解决 模型验证 dbcontext  has been disposed 模型无需 标明[Validator(typeof(Type))],自动解析

            builder.RegisterAssemblyTypes(assemblies)
            .Where(t => t.Name.EndsWith("Validator"))
            .AsImplementedInterfaces()
            .InstancePerLifetimeScope();

            builder.RegisterType <FluentValidation.WebApi.FluentValidationModelValidatorProvider>().As <System.Web.Http.Validation.ModelValidatorProvider>();

            builder.RegisterType <Validators.AutofacValidatorFactory>().As <FluentValidation.IValidatorFactory>().SingleInstance();

            #endregion

            //services


            #region 全景服务类注册
            builder.RegisterType <ProjectService>().As <IProjectService>().InstancePerLifetimeScope();
            builder.RegisterType <SceneService>().As <ISceneService>().InstancePerLifetimeScope();
            builder.RegisterType <LocationService>().As <ILocationService>().InstancePerLifetimeScope();
            builder.RegisterType <BannerService>().As <IBannerService>().InstancePerLifetimeScope();
            builder.RegisterType <HotspotService>().As <IHotspotService>().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<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();
            ////pass MemoryCacheManager as cacheManager (cache settings between requests)


            //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<venderService>().As<IvenderService>().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 <AccountUserService>().As <IAccountUserService>().InstancePerLifetimeScope();
            //builder.RegisterType<CustomerService>().As<IUserStore>().InstancePerLifetimeScope();
            //builder.RegisterType<CustomerService>().As<IAccountUserService>().InstancePerLifetimeScope();

            builder.RegisterType <RefreshTokenService>().As <IRefreshTokenService>().InstancePerLifetimeScope();
            builder.RegisterType <AccountUserRegistrationService>().As <IAccountUserRegistrationService>().InstancePerLifetimeScope();


            builder.RegisterType <DDTalkService>().As <IDDTalkService>().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<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>("qm_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<FileService>().As<IFileService>().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 <TokenAuthenticationService>().As <IAuthenticationService>().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 <AccountUserActivityService>().As <IAccountUserActivityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

            //builder.RegisterType<CodeFirstInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
            //bool databaseInstalled = DataSettingsHelper.DatabaseIsInstalled();
            //if (!databaseInstalled)
            //{
            //    //installation service
            //    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<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();



            //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();
        }
Beispiel #33
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)
        {
            //file provider
            builder.RegisterType <NopFileProvider>().As <INopFileProvider>().InstancePerLifetimeScope();

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

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

            //data layer
            builder.RegisterType <EfDataProviderManager>().As <IDataProviderManager>().InstancePerDependency();
            builder.Register(context => context.Resolve <IDataProviderManager>().DataProvider).As <IDataProvider>().InstancePerDependency();
            builder.Register(context => new NopObjectContext(context.Resolve <DbContextOptions <NopObjectContext> >()))
            .As <IDbContext>().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 <ILocker>()
                .As <IRedisConnectionWrapper>()
                .SingleInstance();
                builder.RegisterType <RedisCacheManager>().As <IStaticCacheManager>().InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>()
                .As <ILocker>()
                .As <IStaticCacheManager>()
                .SingleInstance();
            }

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

            //services
            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 <SearchTermService>().As <ISearchTermService>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <FulltextService>().As <IFulltextService>().InstancePerLifetimeScope();
            builder.RegisterType <MaintenanceService>().As <IMaintenanceService>().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 <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <AclService>().As <IAclService>().InstancePerLifetimeScope();
            builder.RegisterType <GeoLookupService>().As <IGeoLookupService>().InstancePerLifetimeScope();
            builder.RegisterType <CountryService>().As <ICountryService>().InstancePerLifetimeScope();
            builder.RegisterType <StateProvinceService>().As <IStateProvinceService>().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 <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CookieAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UrlRecordService>().As <IUrlRecordService>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <UserActivityService>().As <IUserActivityService>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetService>().As <IWidgetService>().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 <SearchEntity>().As <ISearchEntity>().SingleInstance();
            builder.RegisterType <SearchService>().As <ISearchService>().SingleInstance();

            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 (!DataSettingsManager.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();
            }
        }
        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();

            //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();
                var datacontext = new AFObjectContext(dataProviderSettings.DataConnectionString);
                datacontext.Database.Log = s => Debug.Print(s);
                Database.SetInitializer<AFObjectContext>(null);
                builder.Register<IDbContext>(c => datacontext)
                    .InstancePerLifetimeScope();
            }
            else
            {
                var datacontext = new AFObjectContext(dataSettingsManager.LoadSettings().DataConnectionString);
                datacontext.Database.Log = s => Debug.Print(s);
                Database.SetInitializer<AFObjectContext>(null);
                builder.Register<IDbContext>(
                    c => datacontext)
                    .InstancePerLifetimeScope();
            }

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

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

            builder.RegisterType<CustomerService>().As<ICustomerService>().InstancePerLifetimeScope();

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

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

            builder.RegisterType<GenericAttributeService>().As<IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType<SettingService>().As<ISettingService>().InstancePerLifetimeScope();
            builder.RegisterType<DefaultLogger>().As<ILogger>().InstancePerLifetimeScope();

            builder.RegisterType<OrderProcessingService>().As<IOrderProcessingService>().InstancePerLifetimeScope();
            builder.RegisterType<OrderService>().As<IOrderService>().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();
        }
Beispiel #35
0
        /// <summary>
        /// 注册服务和接口
        /// </summary>
        /// <param name="builder">注册容器</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">配置对象</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            //HTTP上下文和其他相关内容
            builder.Register(c =>
                             //当HttpContext不可用时注册FakeHttpContext
                             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();

            //注册控制器
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //数据层
            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 ExploreObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new ExploreObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }


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


            //缓存管理
            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();

            //services
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();
            builder.RegisterType <UsersService>().As <IUsersService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRegistrationService>().As <ICustomerRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <BannerService>().As <IBannerService>().InstancePerLifetimeScope();
            builder.RegisterType <GameStatisticsService>().As <IGameStatisticsService>().InstancePerLifetimeScope();
            builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();
            builder.RegisterType <ExportManager>().As <IExportManager>().InstancePerLifetimeScope();



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

            builder.RegisterType <DateTimeHelper>().As <IDateTimeHelper>().InstancePerLifetimeScope();

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


            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().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 <SettingService>().As <ISettingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());

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

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

            //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 <CustomerActivityService>().As <ICustomerActivityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"))
            .InstancePerLifetimeScope();

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

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

            //注册事件消费者
            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)
        {
            //file provider
            builder.RegisterType <NopFileProvider>().As <INopFileProvider>().InstancePerLifetimeScope();

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

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

            //data layer
            builder.RegisterType <EfDataProviderManager>().As <IDataProviderManager>().InstancePerDependency();
            builder.Register(context => context.Resolve <IDataProviderManager>().DataProvider).As <IDataProvider>().InstancePerDependency();
            builder.Register(context => new NopObjectContext(context.Resolve <DbContextOptions <NopObjectContext> >()))
            .As <IDbContext>().InstancePerLifetimeScope();

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

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

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

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

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

            //site context
            //builder.RegisterType<WebSiteContext>().As<ISiteContext>().InstancePerLifetimeScope();

            //services
            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 <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <UserRegistrationService>().As <IUserRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <AclService>().As <IAclService>().InstancePerLifetimeScope();
            builder.RegisterType <GeoLookupService>().As <IGeoLookupService>().InstancePerLifetimeScope();
            builder.RegisterType <SiteService>().As <ISiteService>().InstancePerLifetimeScope();
            builder.RegisterType <SiteMappingService>().As <ISiteMappingService>().InstancePerLifetimeScope();
            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTemplateService>().As <IMessageTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailService>().As <IQueuedEmailService>().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 <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CookieAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            //builder.RegisterType<DefaultLogger>().As<ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <NullLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <UserActivityService>().As <IUserActivityService>().InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeProvider>().As <IThemeProvider>().InstancePerLifetimeScope();
            builder.RegisterType <ExternalAuthenticationService>().As <IExternalAuthenticationService>().InstancePerLifetimeScope();
            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
            builder.RegisterType <PictureService>().As <IPictureService>().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();
            }
        }
        protected override void Load(ContainerBuilder builder)
        {
            builder.Register(c => DataSettings.Current).As <DataSettings>().InstancePerDependency();
            builder.Register(x => new EfDataProviderFactory(x.Resolve <DataSettings>())).As <DataProviderFactory>().InstancePerDependency();

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

            if (DataSettings.Current.IsValid())
            {
                // register DB Hooks (only when app was installed properly)

                Func <Type, Type> findHookedType = (t) =>
                {
                    var x = t;
                    while (x != null)
                    {
                        if (x.IsGenericType)
                        {
                            return(x.GetGenericArguments()[0]);
                        }
                        x = x.BaseType;
                    }

                    return(typeof(object));
                };

                var hooks = _typeFinder.FindClassesOfType <IHook>(ignoreInactivePlugins: true);
                foreach (var hook in hooks)
                {
                    var hookedType = findHookedType(hook);

                    var registration = builder.RegisterType(hook)
                                       .As(typeof(IPreActionHook).IsAssignableFrom(hook) ? typeof(IPreActionHook) : typeof(IPostActionHook))
                                       .InstancePerRequest();

                    registration.WithMetadata <HookMetadata>(m =>
                    {
                        m.For(em => em.HookedType, hookedType);
                    });
                }

                builder.Register <IDbContext>(c => new SmartObjectContext(DataSettings.Current.DataConnectionString))
                .PropertiesAutowired(PropertyWiringOptions.None)
                .InstancePerRequest();
            }
            else
            {
                builder.Register <IDbContext>(c => new SmartObjectContext(DataSettings.Current.DataConnectionString)).InstancePerRequest();
            }

            builder.Register <Func <string, IDbContext> >(c =>
            {
                var cc = c.Resolve <IComponentContext>();
                return(named => cc.ResolveNamed <IDbContext>(named));
            });

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

            builder.Register <DbQuerySettings>(c =>
            {
                var storeService = c.Resolve <IStoreService>();
                var aclService   = c.Resolve <IAclService>();

                return(new DbQuerySettings(!aclService.HasActiveAcl, storeService.IsSingleStoreMode()));
            })
            .InstancePerRequest();
        }
Beispiel #38
0
 public static IEnumerable <Type> FindClassesOfType(this ITypeFinder finder, Type assignTypeFrom, bool onlyConcreteClasses = true, bool ignoreInactivePlugins = false)
 {
     return(finder.FindClassesOfType(assignTypeFrom, finder.GetAssemblies(ignoreInactivePlugins), onlyConcreteClasses));
 }
Beispiel #39
0
        /// <summary>
        /// 注册服务与接口
        /// </summary>
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, WebConfig config)
        {
            //Http
            builder.Register(c =>
                             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();

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

            //Controller
            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();

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

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

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

            //Cache
            if (config.RedisCachingEnable)
            {
                builder.RegisterType <RedisConnectionWrapper>().As <IRedisConnectionWrapper>().SingleInstance();
                builder.RegisterType <RedisCacheManager>().As <ICacheManager>().Named <ICacheManager>("ransurotto_cache_static").InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("ransurotto_cache_static").SingleInstance();
            }
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("ransurotto_cache_per_request").InstancePerLifetimeScope();

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

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

            //Settings
            builder.RegisterType <SettingService>().As <ISettingService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("ransurotto_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());

            //Services
            builder.RegisterType <LocalizationService>().As <ILocalizationService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("ransurotto_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("ransurotto_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("ransurotto_cache_static"))
            .InstancePerLifetimeScope();

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

            builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRegistrationService>().As <ICustomerRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReportService>().As <ICustomerReportService>().InstancePerLifetimeScope();

            builder.RegisterType <BlogService>().As <IBlogService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("ransurotto_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <BlogPostTagService>().As <IBlogPostTagService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("ransurotto_cache_static"))
            .InstancePerLifetimeScope();
            builder.RegisterType <IdeaService>().As <IIdeaService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("ransurotto_cache_static"))
            .InstancePerLifetimeScope();

            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <MaintenanceService>().As <IMaintenanceService>().InstancePerLifetimeScope();

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

            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <Logger>().As <ILogger>().InstancePerLifetimeScope();

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

            builder.RegisterType <CustomerActivityService>().As <ICustomerActivityService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("ransurotto_cache_static"))
            .InstancePerLifetimeScope();

            builder.RegisterType <PermissionService>().As <IPermissionService>()
            .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("ransurotto_cache_static"))
            .InstancePerLifetimeScope();

            //Install services
            bool databaseInstalled = DataSettingsHelper.DatabaseIsInstalled();

            if (!databaseInstalled)
            {
                builder.RegisterType <CodeFirstInstallationService>().As <IInstallationService>().InstancePerLifetimeScope();
            }

            //Theme services
            builder.RegisterType <ThemeProvider>().As <IThemeProvider>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeContext>().As <IThemeContext>().InstancePerLifetimeScope();

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

            //Event
            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();
        }
        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();

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

            ////TODO fix compilation warning (below)
            //#pragma warning disable 0618
            //Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
            //var context = new NopObjectContext( "Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) + @"\\Nop.Data.Tests.Db.sdf;Persist Security Info=False");
            //context.Database.Delete();
            //context.Database.Create();
            //builder.Register<IDbContext>(c => context).InstancePerLifetimeScope();
            //builder.Register(x => x.Resolve<BaseDataProviderManager>().LoadDataProvider()).As<IDataProvider>().InstancePerDependency();

            //data layer
            var dataSettingsManager = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings(@"C:\Development\Git\AtrendUsa\Tests\Anko.Plugins.IntegrationTests\settings.txt");//todo ,make relative
            builder.Register(c => dataSettingsManager.LoadSettings(@"C:\Development\Git\AtrendUsa\Tests\Anko.Plugins.IntegrationTests\settings.txt")).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(@"C:\Development\Git\AtrendUsa\Tests\Anko.Plugins.IntegrationTests\settings.txt"));
                var dataProvider = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register<IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register<IDbContext>(c => new NopObjectContext(dataSettingsManager.LoadSettings(@"C:\Development\Git\AtrendUsa\Tests\Anko.Plugins.IntegrationTests\settings.txt").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();

            //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();
            //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<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();

            //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();

            //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();

            //Anko.Plugins.Admin.Uploader
            builder.RegisterType<ProductUploader>().As<IProductUploader>();
            builder.RegisterType<ProductValidator>().As<IProductValidator>();
            builder.RegisterType<ConsoleLogger>().As<ILogger>().InstancePerLifetimeScope();
            builder.RegisterType<ProductResolver>().As<IProductResolver>().InstancePerLifetimeScope();
        }
Beispiel #41
0
 public static IEnumerable <Type> FindClassesOfType <T>(this ITypeFinder finder, IEnumerable <Assembly> assemblies, bool onlyConcreteClasses = true)
 {
     return(finder.FindClassesOfType(typeof(T), assemblies, onlyConcreteClasses));
 }