protected ApiClient GetApiClient()
        {
            var baseUrl   = ConfigurationManager.ConnectionStrings["VirtoCommerceBaseUrl"].ConnectionString;
            var apiClient = new HmacApiClient(baseUrl, ConfigurationManager.AppSettings["vc-public-ApiAppId"], ConfigurationManager.AppSettings["vc-public-ApiSecretKey"]);

            return(apiClient);
        }
Exemplo n.º 2
0
        public void Configuration(IAppBuilder app)
        {
            if (_managerAssembly != null)
            {
                AreaRegistration.RegisterAllAreas();
                CallChildConfigure(app, _managerAssembly, "VirtoCommerce.Platform.Web.Startup", "Configuration", "~/areas/admin", "admin/");
            }

            UnityWebActivator.Start();
            var container = UnityConfig.GetConfiguredContainer();

            //Caching configuration (system runtime memory handle)
            var cacheManager = CacheFactory.FromConfiguration <object>("storefrontCache");

            container.RegisterInstance <ICacheManager <object> >(cacheManager);
            //Because CacheManagerOutputCacheProvider used diff cache manager instance need translate clear region by this way
            //https://github.com/MichaCo/CacheManager/issues/32
            cacheManager.OnClearRegion += (sender, region) =>
            {
                try
                {
                    CacheManagerOutputCacheProvider.Cache.ClearRegion(region.Region);
                }
                catch (Exception)
                {
                }
            };
            cacheManager.OnClear += (sender, args) =>
            {
                try
                {
                    CacheManagerOutputCacheProvider.Cache.Clear();
                }
                catch (Exception)
                {
                }
            };

            var logger = LogManager.GetLogger("default");

            container.RegisterInstance <ILogger>(logger);

            // Workaround for old storefront base URL: remove /api/ suffix since it is already included in every resource address in VirtoCommerce.Client library.
            var baseUrl = ConfigurationManager.ConnectionStrings["VirtoCommerceBaseUrl"].ConnectionString;

            if (baseUrl != null && baseUrl.EndsWith("/api/", StringComparison.OrdinalIgnoreCase))
            {
                var apiPosition = baseUrl.LastIndexOf("/api/", StringComparison.OrdinalIgnoreCase);
                if (apiPosition >= 0)
                {
                    baseUrl = baseUrl.Remove(apiPosition);
                }
            }

            var apiClient = new HmacApiClient(baseUrl, ConfigurationManager.AppSettings["vc-public-ApiAppId"], ConfigurationManager.AppSettings["vc-public-ApiSecretKey"]);

            container.RegisterInstance <ApiClient>(apiClient);

            container.RegisterType <IStoreModuleApi, StoreModuleApi>();
            container.RegisterType <IVirtoCommercePlatformApi, VirtoCommercePlatformApi>();
            container.RegisterType <ICustomerManagementModuleApi, CustomerManagementModuleApi>();
            container.RegisterType <ICommerceCoreModuleApi, CommerceCoreModuleApi>();
            container.RegisterType <ICustomerManagementModuleApi, CustomerManagementModuleApi>();
            container.RegisterType <ICatalogModuleApi, CatalogModuleApi>();
            container.RegisterType <IPricingModuleApi, PricingModuleApi>();
            container.RegisterType <IInventoryModuleApi, InventoryModuleApi>();
            container.RegisterType <IShoppingCartModuleApi, ShoppingCartModuleApi>();
            container.RegisterType <IOrderModuleApi, OrderModuleApi>();
            container.RegisterType <IMarketingModuleApi, MarketingModuleApi>();
            container.RegisterType <ICMSContentModuleApi, CMSContentModuleApi>();
            container.RegisterType <IQuoteModuleApi, QuoteModuleApi>();
            container.RegisterType <ISearchModuleApi, SearchModuleApi>();
            container.RegisterType <IMarketingService, MarketingServiceImpl>();
            container.RegisterType <IPromotionEvaluator, PromotionEvaluator>();
            container.RegisterType <ICartValidator, CartValidator>();
            container.RegisterType <IPricingService, PricingServiceImpl>();
            container.RegisterType <ICustomerService, CustomerServiceImpl>();

            container.RegisterType <ICartBuilder, CartBuilder>();
            container.RegisterType <IQuoteRequestBuilder, QuoteRequestBuilder>();
            container.RegisterType <ICatalogSearchService, CatalogSearchServiceImpl>();
            container.RegisterType <IAuthenticationManager>(new InjectionFactory((context) => HttpContext.Current.GetOwinContext().Authentication));


            container.RegisterType <IStorefrontUrlBuilder, StorefrontUrlBuilder>(new PerRequestLifetimeManager());

            //Register domain events
            container.RegisterType <IEventPublisher <OrderPlacedEvent>, EventPublisher <OrderPlacedEvent> >();
            container.RegisterType <IEventPublisher <UserLoginEvent>, EventPublisher <UserLoginEvent> >();
            //Register event handlers (observers)
            container.RegisterType <IAsyncObserver <OrderPlacedEvent>, CustomerServiceImpl>("Invalidate customer cache when user placed new order");
            container.RegisterType <IAsyncObserver <UserLoginEvent>, CartBuilder>("Merge anonymous cart with loggined user cart");
            container.RegisterType <IAsyncObserver <UserLoginEvent>, QuoteRequestBuilder>("Merge anonymous quote request with loggined user quote");

            // Create new work context for each request
            container.RegisterType <WorkContext, WorkContext>(new PerRequestLifetimeManager());
            Func <WorkContext> workContextFactory = () => container.Resolve <WorkContext>();

            container.RegisterInstance(workContextFactory);

            var themesPath          = ConfigurationManager.AppSettings["vc-public-themes"] ?? "~/App_data/Themes";
            var shopifyLiquidEngine = new ShopifyLiquidThemeEngine(cacheManager, workContextFactory, () => container.Resolve <IStorefrontUrlBuilder>(), ResolveLocalPath(themesPath), "~/themes/assets", "~/themes/global/assets");

            container.RegisterInstance <ILiquidThemeEngine>(shopifyLiquidEngine);
            //Register liquid engine
            ViewEngines.Engines.Add(new DotLiquidThemedViewEngine(shopifyLiquidEngine));

            // Shopify model binders convert Shopify form fields with bad names to VirtoCommerce model properties.
            container.RegisterType <IModelBinderProvider, ShopifyModelBinderProvider>("shopify");

            var staticContentPath = ConfigurationManager.AppSettings["vc-public-pages"] ?? "~/App_data/Pages";
            //Static content service
            var staticContentService = new StaticContentServiceImpl(ResolveLocalPath(staticContentPath), new Markdown(), shopifyLiquidEngine, cacheManager, workContextFactory, () => container.Resolve <IStorefrontUrlBuilder>());

            container.RegisterInstance <IStaticContentService>(staticContentService);

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters, () => container.Resolve <WorkContext>());
            RouteConfig.RegisterRoutes(RouteTable.Routes, () => container.Resolve <WorkContext>(), container.Resolve <ICommerceCoreModuleApi>(), container.Resolve <IStaticContentService>(), cacheManager);
            AuthConfig.ConfigureAuth(app, () => container.Resolve <IStorefrontUrlBuilder>());

            app.Use <WorkContextOwinMiddleware>(container);
            app.UseStageMarker(PipelineStage.ResolveCache);
        }