private static void InitializePlatform(IAppBuilder app, IUnityContainer container, string connectionStringName) { #region Setup database using (var db = new SecurityDbContext(connectionStringName)) { new IdentityDatabaseInitializer().InitializeDatabase(db); } using (var context = new PlatformRepository(connectionStringName, new AuditableInterceptor(), new EntityPrimaryKeyGeneratorInterceptor())) { new PlatformDatabaseInitializer().InitializeDatabase(context); } // Create Hangfire tables new SqlServerStorage(connectionStringName); #endregion Func<IPlatformRepository> platformRepositoryFactory = () => new PlatformRepository(connectionStringName, new AuditableInterceptor(), new EntityPrimaryKeyGeneratorInterceptor()); container.RegisterType<IPlatformRepository>(new InjectionFactory(c => platformRepositoryFactory())); container.RegisterInstance(platformRepositoryFactory); var moduleCatalog = container.Resolve<IModuleCatalog>(); var manifestProvider = container.Resolve<IModuleManifestProvider>(); #region Caching var cacheManager = CacheFactory.Build("platformCache", settings => { //Should be aware to using Web cache cache handle because it not worked in native threads. (Hangfire jobs) settings .WithUpdateMode(CacheUpdateMode.Up) .WithSystemRuntimeCacheHandle("memCacheHandle") .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromDays(1)); }); container.RegisterInstance<ICacheManager<object>>(cacheManager); #endregion #region Settings var platformSettings = new[] { new ModuleManifest { Settings = new[] { new ModuleSettingsGroup { Name = "Platform|Notifications|SendGrid", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendGrid.UserName", ValueType = ModuleSetting.TypeString, Title = "SendGrid UserName", Description = "Your SendGrid account username" }, new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendGrid.Secret", ValueType = ModuleSetting.TypeString, Title = "SendGrid Password", Description = "Your SendGrid account password" } } }, new ModuleSettingsGroup { Name = "Platform|Notifications|SendingJob", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendingJob.TakeCount", ValueType = ModuleSetting.TypeInteger, Title = "Job Take Count", Description = "Take count for sending job" } } }, new ModuleSettingsGroup { Name = "Platform|Notifications|SmtpClient", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SmptClient.Host", ValueType = ModuleSetting.TypeString, Title = "Smtp server host", Description = "Smtp server host" }, new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SmptClient.Port", ValueType = ModuleSetting.TypeInteger, Title = "Smtp server port", Description = "Smtp server port" }, new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SmptClient.Login", ValueType = ModuleSetting.TypeString, Title = "Smtp server login", Description = "Smtp server login" }, new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SmptClient.Password", ValueType = ModuleSetting.TypeString, Title = "Smtp server password", Description = "Smtp server password" } } }, new ModuleSettingsGroup { Name = "Platform|Security", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Security.AccountTypes", ValueType = ModuleSetting.TypeString, Title = "Account types", Description = "Dictionary for possible account types", IsArray = true, ArrayValues = Enum.GetNames(typeof(AccountType)), DefaultValue = AccountType.Manager.ToString() } } } } } }; var settingsManager = new SettingsManager(manifestProvider, platformRepositoryFactory, cacheManager, platformSettings); container.RegisterInstance<ISettingsManager>(settingsManager); #endregion #region Dynamic Properties container.RegisterType<IDynamicPropertyService, DynamicPropertyService>(); #endregion #region Notifications var hubSignalR = GlobalHost.ConnectionManager.GetHubContext<ClientPushHub>(); var notifier = new InMemoryPushNotificationManager(hubSignalR); container.RegisterInstance<IPushNotificationManager>(notifier); var resolver = new LiquidNotificationTemplateResolver(); var notificationTemplateService = new NotificationTemplateServiceImpl(platformRepositoryFactory); var notificationManager = new NotificationManager(resolver, platformRepositoryFactory, notificationTemplateService); //var emailNotificationSendingGateway = new DefaultEmailNotificationSendingGateway(settingsManager); var emailNotificationSendingGateway = new DefaultSmtpEmailNotificationSendingGateway(settingsManager); var defaultSmsNotificationSendingGateway = new DefaultSmsNotificationSendingGateway(); container.RegisterInstance<INotificationTemplateService>(notificationTemplateService); container.RegisterInstance<INotificationManager>(notificationManager); container.RegisterInstance<INotificationTemplateResolver>(resolver); container.RegisterInstance<IEmailNotificationSendingGateway>(emailNotificationSendingGateway); container.RegisterInstance<ISmsNotificationSendingGateway>(defaultSmsNotificationSendingGateway); #endregion #region Assets var assetsConnection = ConfigurationManager.ConnectionStrings["AssetsConnectionString"]; if (assetsConnection != null) { var properties = assetsConnection.ConnectionString.ToDictionary(";", "="); var provider = properties["provider"]; var assetsConnectionString = properties.ToString(";", "=", "provider"); if (string.Equals(provider, FileSystemBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) { var storagePath = HostingEnvironment.MapPath(properties["rootPath"]); var publicUrl = properties["publicUrl"]; var fileSystemBlobProvider = new FileSystemBlobProvider(storagePath, publicUrl); container.RegisterInstance<IBlobStorageProvider>(fileSystemBlobProvider); container.RegisterInstance<IBlobUrlResolver>(fileSystemBlobProvider); } else if (string.Equals(provider, AzureBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) { var azureBlobProvider = new AzureBlobProvider(assetsConnectionString); container.RegisterInstance<IBlobStorageProvider>(azureBlobProvider); container.RegisterInstance<IBlobUrlResolver>(azureBlobProvider); } } #endregion #region Packaging var packagesPath = HostingEnvironment.MapPath(VirtualRoot + "/App_Data/InstalledPackages"); var packageService = new ZipPackageService(moduleCatalog, manifestProvider, packagesPath); container.RegisterInstance<IPackageService>(packageService); var uploadsPath = HostingEnvironment.MapPath(VirtualRoot + "/App_Data/Uploads"); container.RegisterType<ModulesController>(new InjectionConstructor(packageService, uploadsPath, notifier)); #endregion #region ChangeLogging var changeLogService = new ChangeLogService(platformRepositoryFactory); container.RegisterInstance<IChangeLogService>(changeLogService); #endregion #region Security container.RegisterInstance<IPermissionScopeService>(new PermissionScopeService()); container.RegisterType<IRoleManagementService, RoleManagementService>(new ContainerControlledLifetimeManager()); var apiAccountProvider = new ApiAccountProvider(platformRepositoryFactory, cacheManager); container.RegisterInstance<IApiAccountProvider>(apiAccountProvider); container.RegisterType<IClaimsIdentityProvider, ApplicationClaimsIdentityProvider>(new ContainerControlledLifetimeManager()); container.RegisterInstance(app.GetDataProtectionProvider()); container.RegisterType<SecurityDbContext>(new InjectionConstructor(connectionStringName)); container.RegisterType<IUserStore<ApplicationUser>, ApplicationUserStore>(); container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication)); container.RegisterType<ApplicationUserManager>(); container.RegisterType<ApplicationSignInManager>(); var nonEditableUsers = ConfigurationManager.AppSettings.GetValue("VirtoCommerce:NonEditableUsers", string.Empty); container.RegisterInstance<ISecurityOptions>(new SecurityOptions(nonEditableUsers)); container.RegisterType<ISecurityService, SecurityService>(); #endregion #region ExportImport container.RegisterType<IPlatformExportImportManager, PlatformExportImportManager>(); #endregion }
private static void InitializePlatform(IAppBuilder app, IUnityContainer container, string connectionStringName) { #region Setup database using (var db = new SecurityDbContext(connectionStringName)) { new IdentityDatabaseInitializer().InitializeDatabase(db); } using (var context = new PlatformRepository(connectionStringName, new AuditableInterceptor(), new EntityPrimaryKeyGeneratorInterceptor())) { new PlatformDatabaseInitializer().InitializeDatabase(context); } // Create Hangfire tables new SqlServerStorage(connectionStringName); #endregion Func<IPlatformRepository> platformRepositoryFactory = () => new PlatformRepository(connectionStringName, new AuditableInterceptor(), new EntityPrimaryKeyGeneratorInterceptor()); container.RegisterType<IPlatformRepository>(new InjectionFactory(c => platformRepositoryFactory())); container.RegisterInstance<Func<IPlatformRepository>>(platformRepositoryFactory); var moduleCatalog = container.Resolve<IModuleCatalog>(); var manifestProvider = container.Resolve<IModuleManifestProvider>(); #region Caching var cacheProvider = new HttpCacheProvider(); var cacheSettings = new[] { new CacheSettings(CacheGroups.Settings, TimeSpan.FromDays(1)), new CacheSettings(CacheGroups.Security, TimeSpan.FromMinutes(1)), }; var cacheManager = new CacheManager(cacheProvider, cacheSettings); container.RegisterInstance<CacheManager>(cacheManager); #endregion #region Settings var platformSettings = new[] { new ModuleManifest { Settings = new[] { new ModuleSettingsGroup { Name = "Platform|Notifications|SendGrid", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendGrid.UserName", ValueType = ModuleSetting.TypeString, Title = "SendGrid UserName", Description = "Your SendGrid account username" }, new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendGrid.Secret", ValueType = ModuleSetting.TypeString, Title = "SendGrid Password", Description = "Your SendGrid account password" } } }, new ModuleSettingsGroup { Name = "Platform|Notifications|SendingJob", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendingJob.TakeCount", ValueType = ModuleSetting.TypeInteger, Title = "Job Take Count", Description = "Take count for sending job" } } } } } }; var settingsManager = new SettingsManager(manifestProvider, platformRepositoryFactory, cacheManager, platformSettings); container.RegisterInstance<ISettingsManager>(settingsManager); #endregion #region Dynamic Properties container.RegisterType<IDynamicPropertyService, DynamicPropertyService>(); #endregion #region Notifications var hubSignalR = GlobalHost.ConnectionManager.GetHubContext<ClientPushHub>(); var notifier = new InMemoryPushNotificationManager(hubSignalR); container.RegisterInstance<IPushNotificationManager>(notifier); var resolver = new LiquidNotificationTemplateResolver(); var notificationTemplateService = new NotificationTemplateServiceImpl(platformRepositoryFactory); var notificationManager = new NotificationManager(resolver, platformRepositoryFactory, notificationTemplateService); var emailNotificationSendingGateway = new DefaultEmailNotificationSendingGateway(settingsManager); var defaultSmsNotificationSendingGateway = new DefaultSmsNotificationSendingGateway(); container.RegisterInstance<INotificationTemplateService>(notificationTemplateService); container.RegisterInstance<INotificationManager>(notificationManager); container.RegisterInstance<INotificationTemplateResolver>(resolver); container.RegisterInstance<IEmailNotificationSendingGateway>(emailNotificationSendingGateway); container.RegisterInstance<ISmsNotificationSendingGateway>(defaultSmsNotificationSendingGateway); #endregion #region Assets var assetsConnection = ConfigurationManager.ConnectionStrings["AssetsConnectionString"]; if (assetsConnection != null) { var properties = assetsConnection.ConnectionString.ToDictionary(";", "="); var provider = properties["provider"]; var assetsConnectionString = properties.ToString(";", "=", "provider"); if (string.Equals(provider, FileSystemBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) { var fileSystemBlobProvider = new FileSystemBlobProvider(assetsConnectionString); container.RegisterInstance<IBlobStorageProvider>(fileSystemBlobProvider); container.RegisterInstance<IBlobUrlResolver>(fileSystemBlobProvider); } else if (string.Equals(provider, AzureBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) { var azureBlobProvider = new AzureBlobProvider(assetsConnectionString); container.RegisterInstance<IBlobStorageProvider>(azureBlobProvider); container.RegisterInstance<IBlobUrlResolver>(azureBlobProvider); } } #endregion #region Packaging var packagesPath = HostingEnvironment.MapPath("~/App_Data/InstalledPackages"); var packageService = new ZipPackageService(moduleCatalog, manifestProvider, packagesPath); container.RegisterInstance<IPackageService>(packageService); var uploadsPath = HostingEnvironment.MapPath("~/App_Data/Uploads"); container.RegisterType<ModulesController>(new InjectionConstructor(packageService, uploadsPath, notifier)); #endregion #region ChangeLogging var changeLogService = new ChangeLogService(platformRepositoryFactory); container.RegisterInstance<IChangeLogService>(changeLogService); #endregion #region Security var permissionService = new PermissionService(platformRepositoryFactory, manifestProvider, cacheManager); container.RegisterInstance<IPermissionService>(permissionService); container.RegisterType<IRoleManagementService, RoleManagementService>(new ContainerControlledLifetimeManager()); var apiAccountProvider = new ApiAccountProvider(platformRepositoryFactory, cacheManager); container.RegisterInstance<IApiAccountProvider>(apiAccountProvider); container.RegisterType<IClaimsIdentityProvider, ApplicationClaimsIdentityProvider>(new ContainerControlledLifetimeManager()); container.RegisterInstance(app.GetDataProtectionProvider()); container.RegisterType<SecurityDbContext>(new InjectionConstructor(connectionStringName)); container.RegisterType<IUserStore<ApplicationUser>, ApplicationUserStore>(); container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication)); container.RegisterType<ApplicationUserManager>(); container.RegisterType<ApplicationSignInManager>(); var nonEditableUsers = ConfigurationManager.AppSettings.GetValue("VirtoCommerce:NonEditableUsers", string.Empty); container.RegisterInstance<ISecurityOptions>(new SecurityOptions(nonEditableUsers)); container.RegisterType<ISecurityService, SecurityService>(); #endregion #region ExportImport container.RegisterType<IPlatformExportImportManager, PlatformExportImportManager>(); #endregion }