public GenerarGuiaRemisionController(ISerializador serializador) { _serializador = serializador; _documentoXml = _documentoXml = UnityConfig.GetConfiguredContainer() .Resolve <IDocumentoXml>(GetType().Name); }
static ExceptionHandler() { _logger = UnityConfig.GetConfiguredContainer().Resolve <ILogger>(); }
public AssetsController() { var container = UnityConfig.GetConfiguredContainer(); _dbContext = container.Resolve <IAppDbContext>(); }
public void Configuration(IAppBuilder app) { var applicationInsightsKey = Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY"); if (!string.IsNullOrEmpty(applicationInsightsKey)) { TelemetryConfiguration.Active.InstrumentationKey = applicationInsightsKey; } if (_managerAssembly != null) { AreaRegistration.RegisterAllAreas(); CallChildConfigure(app, _managerAssembly, "VirtoCommerce.Platform.Web.Startup", "Configuration", "~/areas/admin", "admin/"); } var appSettings = ConfigurationManager.AppSettings; UnityWebActivator.Start(); var container = UnityConfig.GetConfiguredContainer(); var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); //Cure for System.Runtime.Caching.MemoryCache freezing //https://www.zpqrtbnk.net/posts/appdomains-threads-cultureinfos-and-paracetamol app.SanitizeThreadCulture(); // Caching configuration // Be cautious with SystemWebCacheHandle because it does not work in native threads (Hangfire jobs). var localCache = CacheFactory.FromConfiguration <object>("storefrontCache"); var localCacheManager = new LocalCacheManager(localCache); container.RegisterInstance <ILocalCacheManager>(localCacheManager); //Because CacheManagerOutputCacheProvider used diff cache manager instance need translate clear region by this way //https://github.com/MichaCo/CacheManager/issues/32 localCacheManager.OnClearRegion += (sender, region) => { try { CacheManagerOutputCacheProvider.Cache.ClearRegion(region.Region); } catch { } }; localCacheManager.OnClear += (sender, args) => { try { CacheManagerOutputCacheProvider.Cache.Clear(); } catch { } }; var distributedCache = CacheFactory.Build("distributedCache", settings => { var jsonSerializerSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; var redisCacheEnabled = appSettings.GetValue("VirtoCommerce:Storefront:RedisCache:Enabled", false); var memoryHandlePart = settings .WithJsonSerializer(jsonSerializerSettings, jsonSerializerSettings) .WithUpdateMode(CacheUpdateMode.Up) .WithSystemRuntimeCacheHandle("memory") .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromHours(1)); if (redisCacheEnabled) { var redisCacheConnectionStringName = appSettings.GetValue("VirtoCommerce:Storefront:RedisCache:ConnectionStringName", "RedisCache"); var redisConnectionString = ConfigurationManager.ConnectionStrings[redisCacheConnectionStringName].ConnectionString; memoryHandlePart .And .WithRedisConfiguration("redis", redisConnectionString) .WithRetryTimeout(100) .WithMaxRetries(1000) .WithRedisBackplane("redis") .WithRedisCacheHandle("redis", true) .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromHours(1)); } }); var distributedCacheManager = new DistributedCacheManager(distributedCache); container.RegisterInstance <IDistributedCacheManager>(distributedCacheManager); var logger = LogManager.GetLogger("default"); container.RegisterInstance <ILogger>(logger); // Create new work context for each request container.RegisterType <WorkContext, WorkContext>(new PerRequestLifetimeManager()); Func <WorkContext> workContextFactory = () => container.Resolve <WorkContext>(); container.RegisterInstance(workContextFactory); // 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 apiAppId = appSettings["vc-public-ApiAppId"]; var apiSecretKey = appSettings["vc-public-ApiSecretKey"]; container.RegisterInstance(new HmacCredentials(apiAppId, apiSecretKey)); container.RegisterType <VirtoCommerceApiRequestHandler>(new PerRequestLifetimeManager()); ServicePointManager.UseNagleAlgorithm = false; container.RegisterType <System.Net.Http.HttpClientHandler>(new InjectionFactory(c => new System.Net.Http.HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate })); //Timeout for all API requests. Should be small on production to prevent platform API flood. var apiRequestTimeout = TimeSpan.Parse(appSettings.GetValue("VirtoCommerce:Storefront:ApiRequest:Timeout", "0:0:30")); var baseUri = new Uri(baseUrl); container.RegisterType <ICacheModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new CacheModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <ICartModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new CartModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <ICatalogModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new CatalogModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <IContentModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new ContentModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <ICoreModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new CoreModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <ICustomerModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new CustomerModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <IInventoryModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new InventoryModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <IMarketingModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new MarketingModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <IOrdersModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new OrdersModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <IPlatformModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new PlatformModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <IPricingModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new PricingModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <IQuoteModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new QuoteModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <ISitemapsModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new SitemapsModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <IStoreModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new StoreModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <ISubscriptionModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new SubscriptionModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).DisableRetries().WithTimeout(apiRequestTimeout))); container.RegisterType <IProductRecommendationsModuleApiClient>(new PerRequestLifetimeManager(), new InjectionFactory(c => new ProductRecommendationsModuleApiClient(baseUri, c.Resolve <VirtoCommerceApiRequestHandler>(), c.Resolve <System.Net.Http.HttpClientHandler>()).WithTimeout(apiRequestTimeout))); container.RegisterType <IMarketingService, MarketingServiceImpl>(); container.RegisterType <IPromotionEvaluator, PromotionEvaluator>(); container.RegisterType <ITaxEvaluator, TaxEvaluator>(); container.RegisterType <IPricingService, PricingServiceImpl>(); container.RegisterType <ICustomerService, CustomerServiceImpl>(); container.RegisterType <IMenuLinkListService, MenuLinkListServiceImpl>(); container.RegisterType <ISeoRouteService, SeoRouteService>(); container.RegisterType <IProductAvailabilityService, ProductAvailabilityService>(); container.RegisterType <ICartBuilder, CartBuilder>(); container.RegisterType <IQuoteRequestBuilder, QuoteRequestBuilder>(); container.RegisterType <ICatalogSearchService, CatalogSearchServiceImpl>(); container.RegisterType <IAuthenticationManager>(new InjectionFactory(context => HttpContext.Current.GetOwinContext().Authentication)); container.RegisterType <IUrlBuilder, UrlBuilder>(); container.RegisterType <IStorefrontUrlBuilder, StorefrontUrlBuilder>(new PerRequestLifetimeManager()); container.RegisterType <IRecommendationsService, CognitiveRecommendationsService>("Cognitive"); container.RegisterType <IRecommendationsService, AssociationRecommendationsService>("Association"); //Register domain events container.RegisterType <IEventPublisher <OrderPlacedEvent>, EventPublisher <OrderPlacedEvent> >(); container.RegisterType <IEventPublisher <UserLoginEvent>, EventPublisher <UserLoginEvent> >(); container.RegisterType <IEventPublisher <QuoteRequestUpdatedEvent>, EventPublisher <QuoteRequestUpdatedEvent> >(); //Register event handlers (observers) container.RegisterType <IAsyncObserver <OrderPlacedEvent>, CustomerServiceImpl>("Invalidate customer cache when user placed new order"); container.RegisterType <IAsyncObserver <QuoteRequestUpdatedEvent>, CustomerServiceImpl>("Invalidate customer cache when quote request was updated"); 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"); var cmsContentConnectionString = BlobConnectionString.Parse(ConfigurationManager.ConnectionStrings["ContentConnectionString"].ConnectionString); var themesBasePath = cmsContentConnectionString.RootPath.TrimEnd('/') + "/" + "Themes"; var staticContentBasePath = cmsContentConnectionString.RootPath.TrimEnd('/') + "/" + "Pages"; //Use always file system provider for global theme var globalThemesBlobProvider = new FileSystemContentBlobProvider(ResolveLocalPath("~/App_Data/Themes/default")); IContentBlobProvider themesBlobProvider; IStaticContentBlobProvider staticContentBlobProvider; if ("AzureBlobStorage".Equals(cmsContentConnectionString.Provider, StringComparison.OrdinalIgnoreCase)) { themesBlobProvider = new AzureBlobContentProvider(cmsContentConnectionString.ConnectionString, themesBasePath, localCacheManager); staticContentBlobProvider = new AzureBlobContentProvider(cmsContentConnectionString.ConnectionString, staticContentBasePath, localCacheManager); } else { themesBlobProvider = new FileSystemContentBlobProvider(ResolveLocalPath(themesBasePath)); staticContentBlobProvider = new FileSystemContentBlobProvider(ResolveLocalPath(staticContentBasePath)); } container.RegisterInstance(staticContentBlobProvider); var shopifyLiquidEngine = new ShopifyLiquidThemeEngine(localCacheManager, workContextFactory, () => container.Resolve <IStorefrontUrlBuilder>(), themesBlobProvider, globalThemesBlobProvider, "~/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"); //Static content service var staticContentService = new StaticContentServiceImpl(shopifyLiquidEngine, localCacheManager, workContextFactory, () => container.Resolve <IStorefrontUrlBuilder>(), StaticContentItemFactory.GetContentItemFromPath, staticContentBlobProvider); container.RegisterInstance <IStaticContentService>(staticContentService); //Register generate sitemap background job container.RegisterType <GenerateSitemapJob>(new InjectionFactory(c => new GenerateSitemapJob(themesBlobProvider, c.Resolve <ISitemapsModuleApiClient>(), c.Resolve <IStorefrontUrlBuilder>()))); var changesTrackingEnabled = ConfigurationManager.AppSettings.GetValue("VirtoCommerce:Storefront:ChangesTracking:Enabled", true); var changesTrackingInterval = TimeSpan.Parse(ConfigurationManager.AppSettings.GetValue("VirtoCommerce:Storefront:ChangesTracking:Interval", "0:1:0")); var changesTrackingService = new ChangesTrackingService(changesTrackingEnabled, changesTrackingInterval, container.Resolve <ICacheModuleApiClient>()); container.RegisterInstance <IChangesTrackingService>(changesTrackingService); app.Use <OriginalHostRewriterOwinMiddleware>(container); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters, workContextFactory, () => container.Resolve <CommonController>()); RouteConfig.RegisterRoutes(RouteTable.Routes, container.Resolve <ISeoRouteService>(), workContextFactory, () => container.Resolve <IStorefrontUrlBuilder>()); AuthConfig.ConfigureAuth(app, () => container.Resolve <IStorefrontUrlBuilder>()); var bundleConfig = container.Resolve <BundleConfig>(); bundleConfig.Minify = ConfigurationManager.AppSettings.GetValue("VirtoCommerce:Storefront:OptimizeStaticContent", false); bundleConfig.RegisterBundles(BundleTable.Bundles); //This special binders need because all these types not contains default ctor and Money with Currency properties ModelBinders.Binders.Add(typeof(Model.Cart.Shipment), new CartModelBinder <Model.Cart.Shipment>(workContextFactory)); ModelBinders.Binders.Add(typeof(Model.Cart.Payment), new CartModelBinder <Model.Cart.Payment>(workContextFactory)); ModelBinders.Binders.Add(typeof(Model.Order.PaymentIn), new OrderModelBinder <Model.Order.PaymentIn>(workContextFactory)); ModelBinders.Binders.Add(typeof(Model.Recommendations.RecommendationEvalContext), new ReccomendationsModelBinder <Model.Recommendations.RecommendationEvalContext>()); app.Use <WorkContextOwinMiddleware>(container); app.UseStageMarker(PipelineStage.PostAuthorize); app.Use <StorefrontUrlRewriterOwinMiddleware>(container); app.UseStageMarker(PipelineStage.PostAuthorize); }
public static void RegisterFilterProviders(HttpConfiguration config) { // Add Unity filters provider var providers = config.Services.GetFilterProviders().ToList(); config.Services.Add(typeof(System.Web.Http.Filters.IFilterProvider), new WebApiUnityActionFilterProvider(UnityConfig.GetConfiguredContainer())); var defaultprovider = providers.First(p => p is ActionDescriptorFilterProvider); config.Services.Remove(typeof(System.Web.Http.Filters.IFilterProvider), defaultprovider); }
/// <summary>Disposes the Unity container when the application is shut down.</summary> public static void Shutdown() { var container = UnityConfig.GetConfiguredContainer(); container.Dispose(); }
public void FileProcessortTestInitialize() { this.filePath = AppSettings.Get("MeterFilePath"); container = UnityConfig.GetConfiguredContainer(); }
/// <summary> /// Disposes the Unity container when the application is shut down. /// </summary> public static void Shutdown() { UnityConfig.GetConfiguredContainer().Dispose(); }
public AdminAuthorizeAttribute() { var unityContainer = UnityConfig.GetConfiguredContainer(); _user = unityContainer.Resolve <IUserOps>(); }
public IQueryHandler <TQuery, TResult> GetFor <TQuery, TResult>() where TQuery : IQuery <TResult> { var instance = UnityConfig.GetConfiguredContainer().Resolve <IQueryHandler <TQuery, TResult> >(); return(instance); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ControllerBuilder.Current.SetControllerFactory(new ScopedControllerFactory(UnityConfig.GetConfiguredContainer())); }
public ReflectionLibraryManager() { _reflectedClassBuilder = UnityConfig.GetConfiguredContainer().Resolve <IReflectedClassBuilder>(); }
protected ServiceBase() { _container = UnityConfig.GetConfiguredContainer(); Mapper = _container.Resolve <IPegasusMapper>(); }
public static void Start() { var resolver = new UnityDependencyResolver(UnityConfig.GetConfiguredContainer()); GlobalConfiguration.Configuration.DependencyResolver = resolver; }
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 // Be cautious with SystemWebCacheHandle because it does not work in native threads (Hangfire jobs). var localCache = CacheFactory.FromConfiguration <object>("storefrontCache"); var localCacheManager = new LocalCacheManager(localCache); container.RegisterInstance <ILocalCacheManager>(localCacheManager); //Because CacheManagerOutputCacheProvider used diff cache manager instance need translate clear region by this way //https://github.com/MichaCo/CacheManager/issues/32 localCacheManager.OnClearRegion += (sender, region) => { try { CacheManagerOutputCacheProvider.Cache.ClearRegion(region.Region); } catch { } }; localCacheManager.OnClear += (sender, args) => { try { CacheManagerOutputCacheProvider.Cache.Clear(); } catch { } }; var distributedCache = CacheFactory.Build("distributedCache", settings => { var jsonSerializerSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; var redisCacheEnabled = ConfigurationManager.AppSettings.GetValue("VirtoCommerce:Storefront:RedisCache:Enabled", false); var memoryHandlePart = settings .WithJsonSerializer(jsonSerializerSettings, jsonSerializerSettings) .WithUpdateMode(CacheUpdateMode.Up) .WithSystemRuntimeCacheHandle("memory") .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromHours(1)); if (redisCacheEnabled) { var redisCacheConnectionStringName = ConfigurationManager.AppSettings.GetValue("VirtoCommerce:Storefront:RedisCache:ConnectionStringName", "RedisCache"); var redisConnectionString = ConfigurationManager.ConnectionStrings[redisCacheConnectionStringName].ConnectionString; memoryHandlePart .And .WithRedisConfiguration("redis", redisConnectionString) .WithRetryTimeout(100) .WithMaxRetries(1000) .WithRedisBackplane("redis") .WithRedisCacheHandle("redis", true) .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromHours(1)); } }); var distributedCacheManager = new DistributedCacheManager(distributedCache); container.RegisterInstance <IDistributedCacheManager>(distributedCacheManager); var logger = LogManager.GetLogger("default"); container.RegisterInstance <ILogger>(logger); // Create new work context for each request container.RegisterType <WorkContext, WorkContext>(new PerRequestLifetimeManager()); Func <WorkContext> workContextFactory = () => container.Resolve <WorkContext>(); container.RegisterInstance(workContextFactory); // 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 apiAppId = ConfigurationManager.AppSettings["vc-public-ApiAppId"]; var apiSecretKey = ConfigurationManager.AppSettings["vc-public-ApiSecretKey"]; var apiClient = new StorefrontHmacApiClient(baseUrl, apiAppId, apiSecretKey, workContextFactory); container.RegisterInstance <ApiClient>(apiClient); container.RegisterInstance(new VirtoCommerce.Client.Client.Configuration(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 <IMenuLinkListService, MenuLinkListServiceImpl>(); 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> >(); container.RegisterType <IEventPublisher <QuoteRequestUpdatedEvent>, EventPublisher <QuoteRequestUpdatedEvent> >(); //Register event handlers (observers) container.RegisterType <IAsyncObserver <OrderPlacedEvent>, CustomerServiceImpl>("Invalidate customer cache when user placed new order"); container.RegisterType <IAsyncObserver <QuoteRequestUpdatedEvent>, CustomerServiceImpl>("Invalidate customer cache when quote request was updated"); 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"); var cmsContentConnectionString = BlobConnectionString.Parse(ConfigurationManager.ConnectionStrings["ContentConnectionString"].ConnectionString); var themesBasePath = cmsContentConnectionString.RootPath.TrimEnd('/') + "/" + "Themes"; var staticContentBasePath = cmsContentConnectionString.RootPath.TrimEnd('/') + "/" + "Pages"; //Use always file system provider for global theme var globalThemesBlobProvider = new FileSystemContentBlobProvider(ResolveLocalPath("~/App_Data/Themes/default")); IContentBlobProvider themesBlobProvider; IContentBlobProvider staticContentBlobProvider; if ("AzureBlobStorage".Equals(cmsContentConnectionString.Provider, StringComparison.OrdinalIgnoreCase)) { themesBlobProvider = new AzureBlobContentProvider(cmsContentConnectionString.ConnectionString, themesBasePath, localCacheManager); staticContentBlobProvider = new AzureBlobContentProvider(cmsContentConnectionString.ConnectionString, staticContentBasePath, localCacheManager); } else { themesBlobProvider = new FileSystemContentBlobProvider(ResolveLocalPath(themesBasePath)); staticContentBlobProvider = new FileSystemContentBlobProvider(ResolveLocalPath(staticContentBasePath)); } var shopifyLiquidEngine = new ShopifyLiquidThemeEngine(localCacheManager, workContextFactory, () => container.Resolve <IStorefrontUrlBuilder>(), themesBlobProvider, globalThemesBlobProvider, "~/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 markdownOptions = new MarkdownOptions { LinkEmails = false // Render mailto: links as is without markup transformations }; //Static content service var staticContentService = new StaticContentServiceImpl(new Markdown(markdownOptions), shopifyLiquidEngine, localCacheManager, workContextFactory, () => container.Resolve <IStorefrontUrlBuilder>(), StaticContentItemFactory.GetContentItemFromPath, staticContentBlobProvider); container.RegisterInstance <IStaticContentService>(staticContentService); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters, workContextFactory, () => container.Resolve <CommonController>()); RouteConfig.RegisterRoutes(RouteTable.Routes, workContextFactory, container.Resolve <ICommerceCoreModuleApi>(), container.Resolve <IStaticContentService>(), localCacheManager); AuthConfig.ConfigureAuth(app, () => container.Resolve <IStorefrontUrlBuilder>()); app.Use <WorkContextOwinMiddleware>(container); app.UseStageMarker(PipelineStage.PostAuthorize); app.Use <StorefrontUrlRewriterOwinMiddleware>(container); app.UseStageMarker(PipelineStage.PostAuthorize); }
public BearSlave() { // var _container = new UnityContainer(); //this.bearbotMetric = _container.Resolve<IBearBotMetric>(); this.bearbotMetric = UnityConfig.GetConfiguredContainer().Resolve <IBearBotMetric>(); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); var unityContainer = UnityConfig.GetConfiguredContainer(); IAccountService accountService = unityContainer.Resolve <IAccountService>(); UserLoginResultServiceModel loginResult = await accountService.Login(context.UserName, context.Password, false); if (loginResult == null) { context.SetError("invalid_grant", ErrorResources.UserOrEmailNorValid); return; } else { if (loginResult.Succeeded) { string rolesFlag = accountService.GetRolesKeyFlagsForUser(loginResult.LoggedUser.Id); ClaimsIdentity identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim("sub", context.UserName)); identity.AddClaim(new Claim("role", rolesFlag)); AuthenticationProperties props; AuthenticationTicket authTicket; long recentProjectId = 0; if (rolesFlag.ToUpper() != "C") { IWebApiContentService mainService = unityContainer.Resolve <IWebApiContentService>(); var rmRecentProject = mainService.GetMostRecentProjectId(); if (rmRecentProject.Success) { recentProjectId = rmRecentProject.Value; } } var name = string.Format("{0} {1}", loginResult.LoggedUser.Name, loginResult.LoggedUser.Surname); if (string.IsNullOrWhiteSpace(name)) { name = loginResult.LoggedUser.UserName; } props = new AuthenticationProperties( new Dictionary <string, string> { { "roleFlag", rolesFlag }, { "name", name }, { "rpId", recentProjectId.ToString() } } ); authTicket = new AuthenticationTicket(identity, props); context.Validated(authTicket); } else { context.SetError("invalid_grant", loginResult.FailMessage); return; } } }
public AddContactView() { InitializeComponent(); DataContext = UnityConfig.GetConfiguredContainer().Resolve <AddContactViewModel>(); }
public void Configuration(IAppBuilder app) { 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) => { CacheManagerOutputCacheProvider.Cache.ClearRegion(region.Region); }; cacheManager.OnClear += (sender, args) => { CacheManagerOutputCacheProvider.Cache.Clear(); }; // 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 <ISearchModuleApi, SearchModuleApi>(); container.RegisterType <IMarketingService, MarketingServiceImpl>(); container.RegisterType <IPromotionEvaluator, PromotionEvaluator>(); container.RegisterType <ICartBuilder, CartBuilder>(); container.RegisterType <ICatalogSearchService, CatalogSearchServiceImpl>(); container.RegisterType <IAuthenticationManager>(new InjectionFactory((context) => HttpContext.Current.GetOwinContext().Authentication)); container.RegisterType <IStorefrontUrlBuilder, StorefrontUrlBuilder>(new PerRequestLifetimeManager()); if (_managerAssembly != null) { AreaRegistration.RegisterAllAreas(); CallChildConfigure(app, _managerAssembly, "VirtoCommerce.Platform.Web.Startup", "Configuration", "~/areas/admin", "admin/"); } // Create new work context for each request container.RegisterType <WorkContext, WorkContext>(new PerRequestLifetimeManager()); var shopifyLiquidEngine = new ShopifyLiquidThemeEngine(cacheManager, () => container.Resolve <WorkContext>(), () => container.Resolve <IStorefrontUrlBuilder>(), HostingEnvironment.MapPath("~/App_data/themes"), "~/themes/assets", "~/themes/global/assets"); container.RegisterInstance(shopifyLiquidEngine); //Register liquid engine ViewEngines.Engines.Add(new DotLiquidThemedViewEngine(container.Resolve <ShopifyLiquidThemeEngine>())); // Shopify model binders convert Shopify form fields with bad names to VirtoCommerce model properties. container.RegisterType <IModelBinderProvider, ShopifyModelBinderProvider>("shopify"); //Static content service var staticContentService = new StaticContentServiceImpl(HostingEnvironment.MapPath("~/App_data/Pages"), new Markdown(), shopifyLiquidEngine, cacheManager); container.RegisterInstance <IStaticContentService>(staticContentService); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes, () => container.Resolve <WorkContext>(), container.Resolve <ICommerceCoreModuleApi>(), container.Resolve <IStaticContentService>(), cacheManager); AuthConfig.ConfigureAuth(app); app.Use <WorkContextOwinMiddleware>(container); app.UseStageMarker(PipelineStage.ResolveCache); }
public virtual void Init() { Container = UnityConfig.GetConfiguredContainer(); RegisterTypes(); Log = Container.Resolve <IWrapper <ILog> >(); }