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

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

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

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

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


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

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

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


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

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


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



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


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

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

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
        }
 /// <summary>
 /// Register services and interfaces
 /// </summary>
 /// <param name="builder">Container builder</param>
 /// <param name="typeFinder">Type finder</param>
 /// <param name="config">Config</param>
 public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
 {
     //we cache presentation models between requests
     builder.RegisterType <HomeController>()
     .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"));
     builder.RegisterType <ProductController>()
     .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"));
     builder.RegisterType <CategoryController>()
     .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"));
     builder.RegisterType <CustomerRoleController>()
     .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"));
     builder.RegisterType <DiscountController>()
     .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"));
     builder.RegisterType <ManufacturerController>()
     .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"));
     builder.RegisterType <OrderController>()
     .WithParameter(ResolvedParameter.ForNamed <ICacheManager>("nop_cache_static"));
 }
Ejemplo n.º 4
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)
        {
            //register overridden services and factories
            builder.RegisterType <OverriddenOrderProcessingService>().As <IOrderProcessingService>().InstancePerLifetimeScope();
            builder.RegisterType <OverriddenOrderTotalCalculationService>().As <IOrderTotalCalculationService>().InstancePerLifetimeScope();
            builder.RegisterType <OverriddenShoppingCartModelFactory>().As <Web.Factories.IShoppingCartModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <OverriddenTaxModelFactory>().As <ITaxModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <OverriddenWidgetModelFactory>().As <IWidgetModelFactory>().InstancePerLifetimeScope();

            //register custom services
            builder.RegisterType <AvalaraTaxManager>().AsSelf().InstancePerLifetimeScope();
            builder.RegisterType <TaxTransactionLogService>().As <ITaxTransactionLogService>().InstancePerLifetimeScope();

            //register custom data context
            builder.RegisterPluginDataContext <TaxTransactionLogObjectContext>(AvalaraTaxDefaults.ObjectContextName);
            builder.RegisterType <EfRepository <TaxTransactionLog> >().As <IRepository <TaxTransactionLog> >()
            .WithParameter(ResolvedParameter.ForNamed <IDbContext>(AvalaraTaxDefaults.ObjectContextName))
            .InstancePerLifetimeScope();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="nopConfig">Config</param>
 /// <param name="httpContextAccessor">HTTP context accessor</param>
 public UserAgentHelper(NopConfig nopConfig, IHttpContextAccessor httpContextAccessor)
 {
     this._nopConfig           = nopConfig;
     this._httpContextAccessor = httpContextAccessor;
 }
Ejemplo n.º 6
0
 public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
 {
     //register SquarePaymentManager
     builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerLifetimeScope();
     builder.RegisterType <SubCategoryService>().As <ISubCategoryService>().InstancePerLifetimeScope();
     builder.RegisterType <PostService>().As <IPostService>().InstancePerLifetimeScope();
     builder.RegisterType <CommentService>().As <ICommentService>().InstancePerLifetimeScope();
     builder.RegisterType <CustomersService>().As <ICustomerService>().InstancePerLifetimeScope();
     //builder.RegisterType<CustomersService>().As<ICustomerService>().InstancePerLifetimeScope();
 }
 /// <summary>
 /// Register services and interfaces
 /// </summary>
 /// <param name="builder">Container builder</param>
 /// <param name="typeFinder">Type finder</param>
 /// <param name="config">Config</param>
 public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
 {
     builder.RegisterType <UserModelFactory>().As <IUserModelFactory>()
     .InstancePerLifetimeScope();
 }
Ejemplo n.º 8
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)
        {
            builder.RegisterType <ProductCommentService>().As <IProductCommentService>().InstancePerLifetimeScope();

            builder.RegisterType <ProductCommentModelFactory>().As <IProductCommentModelFactory>().InstancePerLifetimeScope();

            //data context
            builder.RegisterPluginDataContext <ProductCommentsObjectContext>("nop_object_context_product_comments");

            //override required repository with our custom context
            builder.RegisterType <EfRepository <ProductComment> >()
            .As <IRepository <ProductComment> >()
            .WithParameter(ResolvedParameter.ForNamed <IDbContext>("nop_object_context_product_comments"))
            .InstancePerLifetimeScope();

            builder.RegisterType <EfRepository <ProductCommentHelpfulness> >()
            .As <IRepository <ProductCommentHelpfulness> >()
            .WithParameter(ResolvedParameter.ForNamed <IDbContext>("nop_object_context_product_comments"))
            .InstancePerLifetimeScope();

            builder.RegisterType <HostingEnvironment>().As <IHostingEnvironment>().SingleInstance();
        }
Ejemplo n.º 9
0
 public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
 {
     //data context
     this.RegisterPluginDataContext <VendorMembershipContext>(builder, VENDOR_MEMBERSHIP_CONTEXT_NAME);
     RegisterServices(builder);
 }
Ejemplo n.º 10
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)
 {
     //register Worldpay payment manager
     builder.RegisterType <SegmentService>().As <ISegmentService>().InstancePerLifetimeScope();
 }
 public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
 {
     //builder.RegisterType<PinPointSliderModelFactory>().As<IPinPointSliderModelFactory>().InstancePerLifetimeScope();
 }
Ejemplo n.º 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)
        {
            builder.RegisterType <SMSService>().As <ISMSService>().InstancePerLifetimeScope();

            //data context
            this.RegisterPluginDataContext <SMSObjectContext>(builder, "nop_object_context_sms");
            builder.RegisterType <SMSActionFilter>().As <IFilterProvider>().SingleInstance();
            //override required repository with our custom context
            builder.RegisterType <EfRepository <SMSRecord> >()
            .As <IRepository <SMSRecord> >()
            .WithParameter(ResolvedParameter.ForNamed <IDbContext>("nop_object_context_sms"))
            .InstancePerLifetimeScope();
        }
Ejemplo n.º 13
0
 public InstallController(IInstallationLocalizationService locService, NopConfig config)
 {
     this._locService = locService;
     this._config     = config;
 }
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            const string context = "nop_object_context_Bs_product_video";

            builder.RegisterType <ProductVideoRecordService>().As <IProductVideoRecordService>().InstancePerLifetimeScope();

            //data context
            builder.RegisterPluginDataContext <ProductVideoObjectContext>(context);

            //override required repository with our custom context
            builder.RegisterType <EfRepository <ProductVideoRecord> >()
            .As <IRepository <ProductVideoRecord> >()
            .WithParameter(ResolvedParameter.ForNamed <IDbContext>(context))
            .InstancePerLifetimeScope();
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Initialize components and plugins in the nop environment.
 /// </summary>
 /// <param name="config">Config</param>
 public void Initialize(NopConfig config)
 {
     //startup tasks
     RunStartupTasks();
 }
Ejemplo n.º 16
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)
        {
            builder.RegisterType <StorePickupPointService>().As <IStorePickupPointService>().InstancePerLifetimeScope();

            //data context
            builder.RegisterPluginDataContext <StorePickupPointObjectContext>("nop_object_context_pickup_in_store-pickup");

            //override required repository with our custom context
            builder.RegisterType <EfRepository <StorePickupPoint> >().As <IRepository <StorePickupPoint> >()
            .WithParameter(ResolvedParameter.ForNamed <IDbContext>("nop_object_context_pickup_in_store-pickup"))
            .InstancePerLifetimeScope();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            builder.RegisterType <ShippingByDistrictService>().As <IShippingByDistrictService>().InstancePerLifetimeScope();
            builder.RegisterType <ShippingByProductTypeService>().As <IShippingByProductTypeService>().InstancePerLifetimeScope();
            builder.RegisterType <ShippingByCategoryService>().As <IShippingByCategoryService>().InstancePerLifetimeScope();

            //data context
            this.RegisterPluginDataContext <ShippingByDistrictObjectContext>(builder, "nop_object_context_shipping_district_zip");

            //override required repository with our custom context
            builder.RegisterType <EfRepository <ShippingByDistrictRecord> >()
            .As <IRepository <ShippingByDistrictRecord> >()
            .WithParameter(ResolvedParameter.ForNamed <IDbContext>("nop_object_context_shipping_district_zip"))
            .InstancePerLifetimeScope();

            //override required repository with our custom context
            builder.RegisterType <EfRepository <ShippingByProductTypeRecord> >()
            .As <IRepository <ShippingByProductTypeRecord> >()
            .WithParameter(ResolvedParameter.ForNamed <IDbContext>("nop_object_context_shipping_district_zip"))
            .InstancePerLifetimeScope();

            //override required repository with our custom context
            builder.RegisterType <EfRepository <ShippingByCategoryRecord> >()
            .As <IRepository <ShippingByCategoryRecord> >()
            .WithParameter(ResolvedParameter.ForNamed <IDbContext>("nop_object_context_shipping_district_zip"))
            .InstancePerLifetimeScope();
        }
Ejemplo n.º 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)
        {
            //installation localization service
            builder.RegisterType <InstallationLocalizationService>().As <IInstallationLocalizationService>().InstancePerLifetimeScope();

            //common factories
            builder.RegisterType <AclSupportedModelFactory>().As <IAclSupportedModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizedModelFactory>().As <ILocalizedModelFactory>().InstancePerLifetimeScope();

            //admin factories
            builder.RegisterType <BaseAdminModelFactory>().As <IBaseAdminModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ActivityLogModelFactory>().As <IActivityLogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeModelFactory>().As <IAddressAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CommonModelFactory>().As <ICommonModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CountryModelFactory>().As <ICountryModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <UserAttributeModelFactory>().As <IUserAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <UserModelFactory>().As <IUserModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <UserRoleModelFactory>().As <IUserRoleModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountModelFactory>().As <IEmailAccountModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ExternalAuthenticationMethodModelFactory>().As <IExternalAuthenticationMethodModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <HomeModelFactory>().As <IHomeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageModelFactory>().As <ILanguageModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LogModelFactory>().As <ILogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTemplateModelFactory>().As <IMessageTemplateModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <PluginModelFactory>().As <IPluginModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ReportModelFactory>().As <IReportModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailModelFactory>().As <IQueuedEmailModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskModelFactory>().As <IScheduleTaskModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SecurityModelFactory>().As <ISecurityModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SettingModelFactory>().As <ISettingModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <TemplateModelFactory>().As <ITemplateModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetModelFactory>().As <IWidgetModelFactory>().InstancePerLifetimeScope();

            //factories
            builder.RegisterType <Factories.AddressModelFactory>().As <Factories.IAddressModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CommonModelFactory>().As <Factories.ICommonModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CountryModelFactory>().As <Factories.ICountryModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.UserModelFactory>().As <Factories.IUserModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ExternalAuthenticationModelFactory>().As <Factories.IExternalAuthenticationModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ProfileModelFactory>().As <Factories.IProfileModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.WidgetModelFactory>().As <Factories.IWidgetModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.SearchModelFactory>().As <Factories.ISearchModelFactory>().InstancePerLifetimeScope();
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Register services and interfaces
 /// </summary>
 /// <param name="builder">Container builder</param>
 /// <param name="typeFinder">Type finder</param>
 /// <param name="config">Config</param>
 public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
 {
     //register Worldpay payment manager
     builder.RegisterType <WorldpayPaymentManager>().AsSelf().InstancePerLifetimeScope();
 }
Ejemplo n.º 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)
        {
            //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 <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.RunOnAzureWebsites)
            {
                builder.RegisterType <AzureWebsitesMachineNameProvider>().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
            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 <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();

            builder.RegisterType <DiscountService>().As <IDiscountService>().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 <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();

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

            builder.RegisterType <SKL_CaderService>().As <ISKL_CaderService>().InstancePerLifetimeScope();
            builder.RegisterType <SKL_ColorCodeService>().As <ISKL_ColorCodeService>().InstancePerLifetimeScope();
        }
Ejemplo n.º 21
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 <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 (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 <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();
            builder.RegisterType <CacheKeyService>().As <ICacheKeyService>().InstancePerLifetimeScope();
            //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();


            //SVG Content
            builder.RegisterType <SVGContentService>().As <ISVGContentService>().InstancePerLifetimeScope();

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

            //picture service
            if (config.AzureBlobStorageEnabled)
            {
                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();
            }

            // custom code start

            builder.RegisterType <TierpriceService>().As <ITierpriceService>().InstancePerLifetimeScope();


            // custom code end
        }
Ejemplo n.º 22
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)
        {
            //data context
            builder.RegisterPluginDataContext <Data.VendorPostHocObjectContext>("nop_object_context_vendorposthoc");

            //override required repository with our custom context
            builder.RegisterType <EfRepository <VendorConfiguration> >().As <IRepository <VendorConfiguration> >()
            .WithParameter(ResolvedParameter.ForNamed <IDbContext>("nop_object_context_vendorposthoc"))
            .InstancePerLifetimeScope();
            builder.RegisterType <VendorConfigurationService>().As <IVendorConfigurationService>().InstancePerLifetimeScope();
            builder.RegisterType <RetradeShoppingCartService>().As <IShoppingCartService>().InstancePerLifetimeScope();
        }
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            //installation localization service
            builder.RegisterType <InstallationLocalizationService>().As <IInstallationLocalizationService>().InstancePerLifetimeScope();

            //common factories
            builder.RegisterType <AclSupportedModelFactory>().As <IAclSupportedModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizedModelFactory>().As <ILocalizedModelFactory>().InstancePerLifetimeScope();

            //admin factories
            builder.RegisterType <BaseAdminModelFactory>().As <IBaseAdminModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ActivityLogModelFactory>().As <IActivityLogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeModelFactory>().As <IAddressAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CommonModelFactory>().As <ICommonModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CountryModelFactory>().As <ICountryModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <UserAttributeModelFactory>().As <IUserAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <UserModelFactory>().As <IUserModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <UserRoleModelFactory>().As <IUserRoleModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountModelFactory>().As <IEmailAccountModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ExternalAuthenticationMethodModelFactory>().As <IExternalAuthenticationMethodModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <HomeModelFactory>().As <IHomeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageModelFactory>().As <ILanguageModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LogModelFactory>().As <ILogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTemplateModelFactory>().As <IMessageTemplateModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <PluginModelFactory>().As <IPluginModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ReportModelFactory>().As <IReportModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailModelFactory>().As <IQueuedEmailModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskModelFactory>().As <IScheduleTaskModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SecurityModelFactory>().As <ISecurityModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SettingModelFactory>().As <ISettingModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <TemplateModelFactory>().As <ITemplateModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetModelFactory>().As <IWidgetModelFactory>().InstancePerLifetimeScope();

            //factories
            builder.RegisterType <Factories.AddressModelFactory>().As <Factories.IAddressModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CommonModelFactory>().As <Factories.ICommonModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CountryModelFactory>().As <Factories.ICountryModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.UserModelFactory>().As <Factories.IUserModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ExternalAuthenticationModelFactory>().As <Factories.IExternalAuthenticationModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ProfileModelFactory>().As <Factories.IProfileModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.WidgetModelFactory>().As <Factories.IWidgetModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.SearchModelFactory>().As <Factories.ISearchModelFactory>().InstancePerLifetimeScope();

            //signalr hub
            var hubs = typeFinder.FindClassesOfType(typeof(IBaseHub)).ToList();

            foreach (var hub in hubs)
            {
                builder.RegisterType(hub)
                .As(hub.FindInterfaces((type, criteria) =>
                {
                    return(true);
                }, typeof(IBaseHub)))
                .SingleInstance();
            }

            //notification observers

            var observers = typeFinder.FindClassesOfType(typeof(INotificationObserver)).ToList();

            foreach (var observer in observers)
            {
                if (DataSettingsManager.DatabaseIsInstalled)
                {
                    builder.RegisterType(observer)
                    .As(observer.FindInterfaces((type, criteria) =>
                    {
                        return(true);
                    }, typeof(INotificationObserver))).SingleInstance().AutoActivate();
                }
                else
                {
                    builder.RegisterType(observer)
                    .As(observer.FindInterfaces((type, criteria) =>
                    {
                        return(true);
                    }, typeof(INotificationObserver))).SingleInstance();
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Perform file deploy
        /// </summary>
        /// <param name="plug">Plugin file info</param>
        /// <param name="applicationPartManager">Application part manager</param>
        /// <param name="config">Config</param>
        /// <param name="shadowCopyPath">Shadow copy path</param>
        /// <returns>Assembly</returns>
        private static Assembly PerformFileDeploy(string plug, ApplicationPartManager applicationPartManager, NopConfig config, string shadowCopyPath = "")
        {
            var parent = string.IsNullOrEmpty(plug) ? string.Empty : _fileProvider.GetParentDirectory(plug);

            if (string.IsNullOrEmpty(parent))
            {
                throw new InvalidOperationException($"The plugin directory for the {_fileProvider.GetFileName(plug)} file exists in a folder outside of the allowed nopCommerce folder hierarchy");
            }

            if (!config.UsePluginsShadowCopy)
            {
                return(RegisterPluginDefinition(config, applicationPartManager, plug));
            }

            //in order to avoid possible issues we still copy libraries into ~/Plugins/bin/ directory
            if (string.IsNullOrEmpty(shadowCopyPath))
            {
                shadowCopyPath = _shadowCopyFolder;
            }

            _fileProvider.CreateDirectory(shadowCopyPath);
            var shadowCopiedPlug = ShadowCopyFile(plug, shadowCopyPath);

            Assembly shadowCopiedAssembly = null;

            try
            {
                shadowCopiedAssembly = RegisterPluginDefinition(config, applicationPartManager, shadowCopiedPlug);
            }
            catch (FileLoadException)
            {
                if (!config.CopyLockedPluginAssembilesToSubdirectoriesOnStartup || !shadowCopyPath.Equals(_shadowCopyFolder))
                {
                    throw;
                }
            }

            return(shadowCopiedAssembly ?? PerformFileDeploy(plug, applicationPartManager, config, _reserveShadowCopyFolder));
        }
Ejemplo n.º 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, NopConfig config)
 {
     //register PointCheckout payment manager
     builder.RegisterType <PointCheckoutPayPaymentProcessor>().AsSelf().InstancePerLifetimeScope();
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="applicationPartManager">Application part manager</param>
        /// <param name="config">Config</param>
        public static void Initialize(ApplicationPartManager applicationPartManager, NopConfig config)
        {
            if (applicationPartManager == null)
            {
                throw new ArgumentNullException(nameof(applicationPartManager));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            using (new WriteLockDisposable(Locker))
            {
                // TODO: Add verbose exception handling / raising here since this is happening on app startup and could
                // prevent app from starting altogether
                var pluginFolder = _fileProvider.MapPath(NopPluginDefaults.Path);
                _shadowCopyFolder        = _fileProvider.MapPath(NopPluginDefaults.ShadowCopyPath);
                _reserveShadowCopyFolder = _fileProvider.Combine(_fileProvider.MapPath(NopPluginDefaults.ShadowCopyPath), $"{NopPluginDefaults.ReserveShadowCopyPathName}{DateTime.Now.ToFileTimeUtc()}");

                var referencedPlugins   = new List <PluginDescriptor>();
                var incompatiblePlugins = new List <string>();

                try
                {
                    var installedPluginSystemNames = GetInstalledPluginNames(_fileProvider.MapPath(NopPluginDefaults.InstalledPluginsFilePath));

                    Debug.WriteLine("Creating shadow copy folder and querying for DLLs");
                    //ensure folders are created
                    _fileProvider.CreateDirectory(pluginFolder);
                    _fileProvider.CreateDirectory(_shadowCopyFolder);

                    //get list of all files in bin
                    var binFiles = _fileProvider.GetFiles(_shadowCopyFolder, "*", false);
                    if (config.ClearPluginShadowDirectoryOnStartup)
                    {
                        //clear out shadow copied plugins
                        foreach (var f in binFiles)
                        {
                            if (_fileProvider.GetFileName(f).Equals("placeholder.txt", StringComparison.InvariantCultureIgnoreCase))
                            {
                                continue;
                            }

                            Debug.WriteLine("Deleting " + f);
                            try
                            {
                                //ignore index.htm
                                var fileName = _fileProvider.GetFileName(f);
                                if (fileName.Equals("index.htm", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    continue;
                                }

                                _fileProvider.DeleteFile(f);
                            }
                            catch (Exception exc)
                            {
                                Debug.WriteLine("Error deleting file " + f + ". Exception: " + exc);
                            }
                        }

                        //delete all reserve folders
                        foreach (var directory in _fileProvider.GetDirectories(_shadowCopyFolder, NopPluginDefaults.ReserveShadowCopyPathNamePattern))
                        {
                            try
                            {
                                _fileProvider.DeleteDirectory(directory);
                            }
                            catch
                            {
                                //do nothing
                            }
                        }
                    }

                    //load description files
                    foreach (var dfd in GetDescriptionFilesAndDescriptors(pluginFolder))
                    {
                        var descriptionFile  = dfd.Key;
                        var pluginDescriptor = dfd.Value;

                        //ensure that version of plugin is valid
                        if (!pluginDescriptor.SupportedVersions.Contains(NopVersion.CurrentVersion, StringComparer.InvariantCultureIgnoreCase))
                        {
                            incompatiblePlugins.Add(pluginDescriptor.SystemName);
                            continue;
                        }

                        //some validation
                        if (string.IsNullOrWhiteSpace(pluginDescriptor.SystemName))
                        {
                            throw new Exception($"A plugin '{descriptionFile}' has no system name. Try assigning the plugin a unique name and recompiling.");
                        }
                        if (referencedPlugins.Contains(pluginDescriptor))
                        {
                            throw new Exception($"A plugin with '{pluginDescriptor.SystemName}' system name is already defined");
                        }

                        //set 'Installed' property
                        pluginDescriptor.Installed = installedPluginSystemNames
                                                     .FirstOrDefault(x => x.Equals(pluginDescriptor.SystemName, StringComparison.InvariantCultureIgnoreCase)) != null;

                        try
                        {
                            var directoryName = _fileProvider.GetDirectoryName(descriptionFile);
                            if (string.IsNullOrEmpty(directoryName))
                            {
                                throw new Exception($"Directory cannot be resolved for '{_fileProvider.GetFileName(descriptionFile)}' description file");
                            }

                            //get list of all DLLs in plugins (not in bin!)
                            var pluginFiles = _fileProvider.GetFiles(directoryName, "*.dll", false)
                                              //just make sure we're not registering shadow copied plugins
                                              .Where(x => !binFiles.Select(q => q).Contains(x))
                                              .Where(x => IsPackagePluginFolder(_fileProvider.GetDirectoryName(x)))
                                              .ToList();

                            //other plugin description info
                            var mainPluginFile = pluginFiles
                                                 .FirstOrDefault(x => _fileProvider.GetFileName(x).Equals(pluginDescriptor.AssemblyFileName, StringComparison.InvariantCultureIgnoreCase));

                            //plugin have wrong directory
                            if (mainPluginFile == null)
                            {
                                incompatiblePlugins.Add(pluginDescriptor.SystemName);
                                continue;
                            }

                            pluginDescriptor.OriginalAssemblyFile = mainPluginFile;

                            //shadow copy main plugin file
                            pluginDescriptor.ReferencedAssembly = PerformFileDeploy(mainPluginFile, applicationPartManager, config);

                            //load all other referenced assemblies now
                            foreach (var plugin in pluginFiles
                                     .Where(x => !_fileProvider.GetFileName(x).Equals(_fileProvider.GetFileName(mainPluginFile), StringComparison.InvariantCultureIgnoreCase))
                                     .Where(x => !IsAlreadyLoaded(x)))
                            {
                                PerformFileDeploy(plugin, applicationPartManager, config);
                            }

                            //init plugin type (only one plugin per assembly is allowed)
                            foreach (var t in pluginDescriptor.ReferencedAssembly.GetTypes())
                            {
                                if (typeof(IPlugin).IsAssignableFrom(t))
                                {
                                    if (!t.IsInterface)
                                    {
                                        if (t.IsClass && !t.IsAbstract)
                                        {
                                            pluginDescriptor.PluginType = t;
                                            break;
                                        }
                                    }
                                }
                            }

                            referencedPlugins.Add(pluginDescriptor);
                        }
                        catch (ReflectionTypeLoadException ex)
                        {
                            //add a plugin name. this way we can easily identify a problematic plugin
                            var msg = $"Plugin '{pluginDescriptor.FriendlyName}'. ";
                            foreach (var e in ex.LoaderExceptions)
                            {
                                msg += e.Message + Environment.NewLine;
                            }

                            var fail = new Exception(msg, ex);
                            throw fail;
                        }
                        catch (Exception ex)
                        {
                            //add a plugin name. this way we can easily identify a problematic plugin
                            var msg = $"Plugin '{pluginDescriptor.FriendlyName}'. {ex.Message}";

                            var fail = new Exception(msg, ex);
                            throw fail;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = string.Empty;
                    for (var e = ex; e != null; e = e.InnerException)
                    {
                        msg += e.Message + Environment.NewLine;
                    }

                    var fail = new Exception(msg, ex);
                    throw fail;
                }

                ReferencedPlugins   = referencedPlugins;
                IncompatiblePlugins = incompatiblePlugins;
            }
        }
 public CommonModelFactory(AdminAreaSettings adminAreaSettings,
                           CatalogSettings catalogSettings,
                           CurrencySettings currencySettings,
                           IActionContextAccessor actionContextAccessor,
                           IAuthenticationPluginManager authenticationPluginManager,
                           ICurrencyService currencyService,
                           ICustomerService customerService,
                           IDateTimeHelper dateTimeHelper,
                           INopFileProvider fileProvider,
                           IExchangeRatePluginManager exchangeRatePluginManager,
                           IHttpContextAccessor httpContextAccessor,
                           ILanguageService languageService,
                           ILocalizationService localizationService,
                           IMaintenanceService maintenanceService,
                           IMeasureService measureService,
                           IOrderService orderService,
                           IPaymentPluginManager paymentPluginManager,
                           IPickupPluginManager pickupPluginManager,
                           IPluginService pluginService,
                           IProductService productService,
                           IReturnRequestService returnRequestService,
                           ISearchTermService searchTermService,
                           IShippingPluginManager shippingPluginManager,
                           IStaticCacheManager cacheManager,
                           IStoreContext storeContext,
                           IStoreService storeService,
                           ITaxPluginManager taxPluginManager,
                           IUrlHelperFactory urlHelperFactory,
                           IUrlRecordService urlRecordService,
                           IWebHelper webHelper,
                           IWidgetPluginManager widgetPluginManager,
                           IWorkContext workContext,
                           MeasureSettings measureSettings,
                           NopConfig nopConfig,
                           NopHttpClient nopHttpClient,
                           ProxySettings proxySettings)
 {
     _adminAreaSettings           = adminAreaSettings;
     _catalogSettings             = catalogSettings;
     _currencySettings            = currencySettings;
     _actionContextAccessor       = actionContextAccessor;
     _authenticationPluginManager = authenticationPluginManager;
     _currencyService             = currencyService;
     _customerService             = customerService;
     _dateTimeHelper            = dateTimeHelper;
     _exchangeRatePluginManager = exchangeRatePluginManager;
     _httpContextAccessor       = httpContextAccessor;
     _languageService           = languageService;
     _localizationService       = localizationService;
     _maintenanceService        = maintenanceService;
     _measureService            = measureService;
     _fileProvider          = fileProvider;
     _orderService          = orderService;
     _paymentPluginManager  = paymentPluginManager;
     _pickupPluginManager   = pickupPluginManager;
     _pluginService         = pluginService;
     _productService        = productService;
     _returnRequestService  = returnRequestService;
     _searchTermService     = searchTermService;
     _shippingPluginManager = shippingPluginManager;
     _cacheManager          = cacheManager;
     _storeContext          = storeContext;
     _storeService          = storeService;
     _taxPluginManager      = taxPluginManager;
     _urlHelperFactory      = urlHelperFactory;
     _urlRecordService      = urlRecordService;
     _webHelper             = webHelper;
     _widgetPluginManager   = widgetPluginManager;
     _workContext           = workContext;
     _measureSettings       = measureSettings;
     _nopConfig             = nopConfig;
     _nopHttpClient         = nopHttpClient;
     _proxySettings         = proxySettings;
 }
Ejemplo n.º 28
0
        private void InitializeContainer(ContainerConfigurer configurer, EventBroker broker, NopConfig config)
        {
            var builder = new ContainerBuilder();

            _containerManager = new ContainerManager(builder.Build());
            configurer.Configure(this, _containerManager, broker, config);
        }
Ejemplo n.º 29
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)
        {
            //installation localization service
            builder.RegisterType <InstallationLocalizationService>().As <IInstallationLocalizationService>().InstancePerLifetimeScope();

            //common factories
            builder.RegisterType <AclSupportedModelFactory>().As <IAclSupportedModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <DiscountSupportedModelFactory>().As <IDiscountSupportedModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizedModelFactory>().As <ILocalizedModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <StoreMappingSupportedModelFactory>().As <IStoreMappingSupportedModelFactory>().InstancePerLifetimeScope();

            //admin factories
            builder.RegisterType <BaseAdminModelFactory>().As <IBaseAdminModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ActivityLogModelFactory>().As <IActivityLogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeModelFactory>().As <IAddressAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <AffiliateModelFactory>().As <IAffiliateModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <BlogModelFactory>().As <IBlogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CampaignModelFactory>().As <ICampaignModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryModelFactory>().As <ICategoryModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CheckoutAttributeModelFactory>().As <ICheckoutAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CommonModelFactory>().As <ICommonModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CountryModelFactory>().As <ICountryModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CurrencyModelFactory>().As <ICurrencyModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeModelFactory>().As <ICustomerAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerModelFactory>().As <ICustomerModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRoleModelFactory>().As <ICustomerRoleModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <DiscountModelFactory>().As <IDiscountModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountModelFactory>().As <IEmailAccountModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ExternalAuthenticationMethodModelFactory>().As <IExternalAuthenticationMethodModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ForumModelFactory>().As <IForumModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <GiftCardModelFactory>().As <IGiftCardModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <HomeModelFactory>().As <IHomeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageModelFactory>().As <ILanguageModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LogModelFactory>().As <ILogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ManufacturerModelFactory>().As <IManufacturerModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <MeasureModelFactory>().As <IMeasureModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTemplateModelFactory>().As <IMessageTemplateModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <NewsletterSubscriptionModelFactory>().As <INewsletterSubscriptionModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <NewsModelFactory>().As <INewsModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <OrderModelFactory>().As <IOrderModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <PaymentModelFactory>().As <IPaymentModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <PluginModelFactory>().As <IPluginModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <PollModelFactory>().As <IPollModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ProductModelFactory>().As <IProductModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ProductAttributeModelFactory>().As <IProductAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ProductReviewModelFactory>().As <IProductReviewModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ReportModelFactory>().As <IReportModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailModelFactory>().As <IQueuedEmailModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <RecurringPaymentModelFactory>().As <IRecurringPaymentModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ReturnRequestModelFactory>().As <IReturnRequestModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ReviewTypeModelFactory>().As <IReviewTypeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskModelFactory>().As <IScheduleTaskModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SecurityModelFactory>().As <ISecurityModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SettingModelFactory>().As <ISettingModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ShippingModelFactory>().As <IShippingModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ShoppingCartModelFactory>().As <IShoppingCartModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SpecificationAttributeModelFactory>().As <ISpecificationAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <StoreModelFactory>().As <IStoreModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <TaxModelFactory>().As <ITaxModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <TemplateModelFactory>().As <ITemplateModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <TopicModelFactory>().As <ITopicModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <VendorAttributeModelFactory>().As <IVendorAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <VendorModelFactory>().As <IVendorModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetModelFactory>().As <IWidgetModelFactory>().InstancePerLifetimeScope();

            //factories
            builder.RegisterType <Factories.AddressModelFactory>().As <Factories.IAddressModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.BlogModelFactory>().As <Factories.IBlogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CatalogModelFactory>().As <Factories.ICatalogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CheckoutModelFactory>().As <Factories.ICheckoutModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CommonModelFactory>().As <Factories.ICommonModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CountryModelFactory>().As <Factories.ICountryModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CustomerModelFactory>().As <Factories.ICustomerModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ForumModelFactory>().As <Factories.IForumModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ExternalAuthenticationModelFactory>().As <Factories.IExternalAuthenticationModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.NewsModelFactory>().As <Factories.INewsModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.NewsletterModelFactory>().As <Factories.INewsletterModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.OrderModelFactory>().As <Factories.IOrderModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.PollModelFactory>().As <Factories.IPollModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.PrivateMessagesModelFactory>().As <Factories.IPrivateMessagesModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ProductModelFactory>().As <Factories.IProductModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ProfileModelFactory>().As <Factories.IProfileModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ReturnRequestModelFactory>().As <Factories.IReturnRequestModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ShoppingCartModelFactory>().As <Factories.IShoppingCartModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.TopicModelFactory>().As <Factories.ITopicModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.VendorModelFactory>().As <Factories.IVendorModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.WidgetModelFactory>().As <Factories.IWidgetModelFactory>().InstancePerLifetimeScope();
        }
Ejemplo n.º 30
0
 public ThemeProvider(NopConfig nopConfig, IWebHelper webHelper)
 {
     _basePath = webHelper.MapPath(nopConfig.ThemeBasePath);
     LoadConfigurations();
 }