/// <summary> /// Initialize engine /// </summary> /// <param name="services">Collection of service descriptors</param> public static void Initialize(IServiceCollection services, IConfiguration configuration) { //set base application path var provider = services.BuildServiceProvider(); var hostingEnvironment = provider.GetRequiredService <IWebHostEnvironment>(); var config = new GrandConfig(); configuration.GetSection("Grand").Bind(config); CommonHelper.WebRootPath = hostingEnvironment.WebRootPath; CommonHelper.BaseDirectory = hostingEnvironment.ContentRootPath; CommonHelper.CacheTimeMinutes = config.DefaultCacheTimeMinutes; CommonHelper.CookieAuthExpires = config.CookieAuthExpires > 0 ? config.CookieAuthExpires : 24 * 365; CommonHelper.AllowToJsonResponse = config.AllowToJsonResponse; //register mongo mappings MongoDBMapperConfiguration.RegisterMongoDBMappings(); //initialize plugins var mvcCoreBuilder = services.AddMvcCore(); //PluginManager.Initialize(mvcCoreBuilder, config); //initialize CTX sctipts //RoslynCompiler.Initialize(mvcCoreBuilder.PartManager, config); }
public RedisMessageBus(ISubscriber subscriber, IServiceProvider serviceProvider, GrandConfig grandConfig) { _subscriber = subscriber; _serviceProvider = serviceProvider; _grandConfig = grandConfig; SubscribeAsync(); }
/// <summary> /// Add and configure any of the middleware /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { var config = new GrandConfig(); configuration.GetSection("Grand").Bind(config); //add settings services.AddSettings(); //compression services.AddResponseCompression(); //add options feature services.AddOptions(); //add HTTP sesion state feature services.AddHttpSession(config); //add anti-forgery services.AddAntiForgery(config); //add localization services.AddLocalization(); //add theme support services.AddThemes(); //add WebEncoderOptions services.AddWebEncoder(); }
private void RegisterMediaService(IServiceCollection serviceCollection, GrandConfig config) { serviceCollection.AddScoped <IMimeMappingService, MimeMappingService>(x => { var provider = new FileExtensionContentTypeProvider(); return(new MimeMappingService(provider)); }); //picture service var useAzureBlobStorage = !String.IsNullOrEmpty(config.AzureBlobStorageConnectionString); var useAmazonBlobStorage = (!String.IsNullOrEmpty(config.AmazonAwsAccessKeyId) && !String.IsNullOrEmpty(config.AmazonAwsSecretAccessKey) && !String.IsNullOrEmpty(config.AmazonBucketName) && !String.IsNullOrEmpty(config.AmazonRegion)); if (useAzureBlobStorage) { //Windows Azure BLOB serviceCollection.AddScoped <IPictureService, AzurePictureService>(); } else if (useAmazonBlobStorage) { //Amazon S3 Simple Storage Service serviceCollection.AddScoped <IPictureService, AmazonPictureService>(); } else { //standard file system serviceCollection.AddScoped <IPictureService, PictureService>(); } serviceCollection.AddScoped <IDownloadService, DownloadService>(); }
/// <summary> /// Register mapping /// </summary> /// <param name="config">Config</param> protected virtual void RegisterMapperConfiguration(GrandConfig config) { //dependencies var typeFinder = new WebAppTypeFinder(); //register mapper configurations provided by other assemblies var mcTypes = typeFinder.FindClassesOfType <IMapperConfiguration>(); var mcInstances = new List <IMapperConfiguration>(); foreach (var mcType in mcTypes) { mcInstances.Add((IMapperConfiguration)Activator.CreateInstance(mcType)); } //sort mcInstances = mcInstances.AsQueryable().OrderBy(t => t.Order).ToList(); //get configurations var configurationActions = new List <Action <IMapperConfigurationExpression> >(); foreach (var mc in mcInstances) { configurationActions.Add(mc.GetConfiguration()); } //register AutoMapperConfiguration.Init(configurationActions); }
/// <summary> /// Register MongoDB mappings /// </summary> /// <param name="config">Config</param> public static void RegisterMongoDBMappings(GrandConfig config) { BsonSerializer.RegisterSerializer(typeof(decimal), new DecimalSerializer(BsonType.Decimal128)); BsonSerializer.RegisterSerializer(typeof(decimal?), new NullableSerializer <decimal>(new DecimalSerializer(BsonType.Decimal128))); BsonSerializer.RegisterSerializer(typeof(DateTime), new BsonUtcDateTimeSerializer()); //global set an equivalent of [BsonIgnoreExtraElements] for every Domain Model var cp = new ConventionPack(); cp.Add(new IgnoreExtraElementsConvention(true)); ConventionRegistry.Register("ApplicationConventions", cp, t => true); //BsonClassMap.RegisterClassMap<ProductCategory>(cm => //{ // cm.AutoMap(); // cm.UnmapMember(c => c.ProductId); //}); //BsonClassMap.RegisterClassMap<ProductManufacturer>(cm => //{ // cm.AutoMap(); // cm.UnmapMember(c => c.ProductId); //}); //BsonClassMap.RegisterClassMap<CustomerReminderHistory>(cm => //{ // cm.AutoMap(); // cm.UnmapMember(c => c.ReminderRule); // cm.UnmapMember(c => c.HistoryStatus); //}); }
public InstallController(GrandConfig config, ICacheManager cacheManager, IServiceProvider serviceProvider) { _config = config; _cacheManager = cacheManager; _serviceProvider = serviceProvider; }
public void Register(ContainerBuilder builder, ITypeFinder typeFinder, GrandConfig config) { builder.RegisterType <VPAPlugin>().InstancePerLifetimeScope(); builder.RegisterType <ProductService>().As <IProductService>().InstancePerLifetimeScope(); builder.RegisterType <ProductServiceOver>().As <Grand.Services.Catalog.IProductService>().InstancePerLifetimeScope(); builder.RegisterType <GetSearchProductsQueryHandlerOver>().As <IRequestHandler <GetSearchProductsQuery, (IPagedList <Core.Domain.Catalog.Product>, IList <string>)> >().InstancePerLifetimeScope(); }
/// <summary> /// Configure static file serving /// </summary> /// <param name="application">Builder for configuring an application's request pipeline</param> public static void UseGrandStaticFiles(this IApplicationBuilder application, GrandConfig grandConfig) { //static files application.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = ctx => { if (!String.IsNullOrEmpty(grandConfig.StaticFilesCacheControl)) ctx.Context.Response.Headers.Append(HeaderNames.CacheControl, grandConfig.StaticFilesCacheControl); } }); //themes application.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(CommonHelper.MapPath("Themes")), RequestPath = new PathString("/Themes"), OnPrepareResponse = ctx => { if (!String.IsNullOrEmpty(grandConfig.StaticFilesCacheControl)) ctx.Context.Response.Headers.Append(HeaderNames.CacheControl, grandConfig.StaticFilesCacheControl); } }); //plugins application.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(CommonHelper.MapPath("Plugins")), RequestPath = new PathString("/Plugins"), OnPrepareResponse = ctx => { if (!String.IsNullOrEmpty(grandConfig.StaticFilesCacheControl)) ctx.Context.Response.Headers.Append(HeaderNames.CacheControl, grandConfig.StaticFilesCacheControl); } }); }
/// <summary> /// Register dependencies using Autofac /// </summary> /// <param name="grandConfiguration">Startup Grand configuration parameters</param> /// <param name="services">Collection of service descriptors</param> /// <param name="typeFinder">Type finder</param> protected virtual IServiceProvider RegisterDependencies(GrandConfig grandConfiguration, IServiceCollection services, ITypeFinder typeFinder) { var containerBuilder = new ContainerBuilder(); //register engine containerBuilder.RegisterInstance(this).As <IEngine>().SingleInstance(); //register type finder containerBuilder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance(); //find dependency registrars provided by other assemblies var dependencyRegistrars = typeFinder.FindClassesOfType <IDependencyRegistrar>(); //create and sort instances of dependency registrars var instances = dependencyRegistrars //.Where(startup => PluginManager.FindPlugin(startup).Return(plugin => plugin.Installed, true)) //ignore not installed plugins .Select(dependencyRegistrar => (IDependencyRegistrar)Activator.CreateInstance(dependencyRegistrar)) .OrderBy(dependencyRegistrar => dependencyRegistrar.Order); //register all provided dependencies foreach (var dependencyRegistrar in instances) { dependencyRegistrar.Register(containerBuilder, typeFinder, grandConfiguration); } //populate Autofac container builder with the set of registered service descriptors containerBuilder.Populate(services); //create service provider _serviceProvider = new AutofacServiceProvider(containerBuilder.Build()); return(_serviceProvider); }
/// <summary> /// Add and configure any of the middleware /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { var config = new GrandConfig(); configuration.GetSection("Grand").Bind(config); //add settings // services.AddSettings(); //compression //services.AddResponseCompression(); //add options feature //services.AddOptions(); //add HTTP sesion state feature services.AddHttpSession(config); //add anti-forgery services.AddAntiForgery(config); //add localization //services.AddLocalization(); //add theme support //services.AddThemes(); //add WebEncoderOptions services.AddWebEncoder(); services.AddRouting(options => { // options.ConstraintMap["lang"] = typeof(LanguageParameterTransformer); }); }
private void RegisterMediaService(ContainerBuilder builder, GrandConfig config) { var provider = new FileExtensionContentTypeProvider(); builder.RegisterType <MimeMappingService>().As <IMimeMappingService>() .WithParameter(new TypedParameter(typeof(FileExtensionContentTypeProvider), provider)) .InstancePerLifetimeScope(); //picture service var useAzureBlobStorage = !String.IsNullOrEmpty(config.AzureBlobStorageConnectionString); var useAmazonBlobStorage = (!String.IsNullOrEmpty(config.AmazonAwsAccessKeyId) && !String.IsNullOrEmpty(config.AmazonAwsSecretAccessKey) && !String.IsNullOrEmpty(config.AmazonBucketName) && !String.IsNullOrEmpty(config.AmazonRegion)); if (useAzureBlobStorage) { //Windows Azure BLOB builder.RegisterType <AzurePictureService>().As <IPictureService>().InstancePerLifetimeScope(); } else if (useAmazonBlobStorage) { //Amazon S3 Simple Storage Service builder.RegisterType <AmazonPictureService>().As <IPictureService>().InstancePerLifetimeScope(); } else { //standard file system builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope(); } builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope(); }
public WebWorkContext(IHttpContextAccessor httpContextAccessor, IGrandAuthenticationService authenticationService, IApiAuthenticationService apiauthenticationService, ICurrencyService currencyService, ICustomerService customerService, IGenericAttributeService genericAttributeService, ILanguageService languageService, IStoreContext storeContext, IStoreMappingService storeMappingService, IVendorService vendorService, LocalizationSettings localizationSettings, TaxSettings taxSettings, GrandConfig config) { _httpContextAccessor = httpContextAccessor; _authenticationService = authenticationService; _apiauthenticationService = apiauthenticationService; _currencyService = currencyService; _customerService = customerService; _genericAttributeService = genericAttributeService; _languageService = languageService; _storeContext = storeContext; _storeMappingService = storeMappingService; _vendorService = vendorService; _localizationSettings = localizationSettings; _taxSettings = taxSettings; _config = config; }
public AzurePictureService(IRepository <Picture> pictureRepository, ISettingService settingService, ILogger logger, IMediator mediator, IWebHostEnvironment hostingEnvironment, IStoreContext storeContext, ICacheManager cacheManager, MediaSettings mediaSettings, GrandConfig config) : base(pictureRepository, settingService, logger, mediator, hostingEnvironment, storeContext, cacheManager, mediaSettings) { _config = config; if (string.IsNullOrEmpty(_config.AzureBlobStorageConnectionString)) { throw new Exception("Azure connection string for BLOB is not specified"); } if (string.IsNullOrEmpty(_config.AzureBlobStorageContainerName)) { throw new Exception("Azure container name for BLOB is not specified"); } if (string.IsNullOrEmpty(_config.AzureBlobStorageEndPoint)) { throw new Exception("Azure end point for BLOB is not specified"); } container = new BlobContainerClient(_config.AzureBlobStorageConnectionString, _config.AzureBlobStorageContainerName); }
/// <summary> /// ConfigureContainer is where you can register things directly /// with Autofac. This runs after ConfigureServices so the things /// here will override registrations made in ConfigureServices. /// </summary> /// <param name="builder"></param> /// <param name="configuration"></param> public void ConfigureContainer(ContainerBuilder builder, IConfiguration configuration) { var typeFinder = new WebAppTypeFinder(); //register type finder builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance(); //find dependency registrars provided by other assemblies var dependencyRegistrars = typeFinder.FindClassesOfType <IDependencyRegistrar>(); //create and sort instances of dependency registrars var instances = dependencyRegistrars //.Where(startup => PluginManager.FindPlugin(startup).Return(plugin => plugin.Installed, true)) //ignore not installed plugins .Select(dependencyRegistrar => (IDependencyRegistrar)Activator.CreateInstance(dependencyRegistrar)) .OrderBy(dependencyRegistrar => dependencyRegistrar.Order); var config = new GrandConfig(); configuration.GetSection("Grand").Bind(config); //register all provided dependencies foreach (var dependencyRegistrar in instances) { dependencyRegistrar.Register(builder, typeFinder, config); } }
/// <summary> /// Add and configure services /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> /// <returns>Service provider</returns> public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { //find startup configurations provided by other assemblies var typeFinder = new WebAppTypeFinder(); var startupConfigurations = typeFinder.FindClassesOfType <IGrandStartup>(); //create and sort instances of startup configurations var instances = startupConfigurations .Where(startup => PluginManager.FindPlugin(startup).Return(plugin => plugin.Installed, true)) //ignore not installed plugins .Select(startup => (IGrandStartup)Activator.CreateInstance(startup)) .OrderBy(startup => startup.Order); //configure services foreach (var instance in instances) { instance.ConfigureServices(services, configuration); } //register mapper configurations AddAutoMapper(services, typeFinder); //Add attributes to register custom type converters RegisterTypeConverter(); var config = new GrandConfig(); configuration.GetSection("Grand").Bind(config); //run startup tasks if (!config.IgnoreStartupTasks) { RunStartupTasks(typeFinder); } }
public void Register(ContainerBuilder builder, ITypeFinder typeFinder, GrandConfig config) { builder.RegisterType <ExamplePlugin>().InstancePerLifetimeScope(); builder.RegisterType <ExampleService>().As <IExampleService>().InstancePerLifetimeScope(); builder.RegisterType <OverrideProductService>().As <IProductService>().InstancePerLifetimeScope(); builder.RegisterType <ExampleTask>().As <IScheduleTask>().InstancePerLifetimeScope(); builder.RegisterType <TestActionFilter2>().InstancePerLifetimeScope(); }
/// <summary> /// Ctor /// </summary> /// <param name="cacheManager">Cache manager</param> /// <param name="urlRecordRepository">URL record repository</param> /// <param name="localizationSettings">Localization settings</param> public UrlRecordService(ICacheManager cacheManager, IRepository <UrlRecord> urlRecordRepository, GrandConfig config) { _cacheManager = cacheManager; _urlRecordRepository = urlRecordRepository; _config = config; }
public InstallController(IInstallationLocalizationService locService, GrandConfig config, ICacheManager cacheManager, IServiceProvider serviceProvider) { _locService = locService; _config = config; _cacheManager = cacheManager; _serviceProvider = serviceProvider; }
public InstallController(GrandConfig config, ICacheBase cacheManager, IServiceProvider serviceProvider, IMediator mediator) { _config = config; _cacheBase = cacheManager; _serviceProvider = serviceProvider; _mediator = mediator; }
public SlugRouteTransformer( IUrlRecordService urlRecordService, ILanguageService languageService, GrandConfig config) { _urlRecordService = urlRecordService; _languageService = languageService; _config = config; }
public CheckLanguageSeoCodeFilter(IWebHelper webHelper, IWorkContext workContext, ILanguageService languageService, GrandConfig config) { _webHelper = webHelper; _workContext = workContext; _languageService = languageService; _config = config; }
/// <summary> /// Ctor /// </summary> /// <param name="customerSettings">Customer settings</param> /// <param name="customerService">Customer service</param> /// <param name="httpContextAccessor">HTTP context accessor</param> public CookieAuthenticationService(CustomerSettings customerSettings, ICustomerService customerService, IHttpContextAccessor httpContextAccessor, GrandConfig grandConfig) { _customerSettings = customerSettings; _customerService = customerService; _httpContextAccessor = httpContextAccessor; _grandConfig = grandConfig; }
public GetRobotsTextFileHandler(IStoreContext storeContext, ILanguageService languageService, IWebHelper webHelper, GrandConfig config) { _storeContext = storeContext; _languageService = languageService; _webHelper = webHelper; _config = config; }
private void RegisterCache(IServiceCollection serviceCollection, GrandConfig config) { serviceCollection.AddSingleton <ICacheBase, MemoryCacheBase>(); if (config.RedisPubSubEnabled) { var redis = ConnectionMultiplexer.Connect(config.RedisPubSubConnectionString); serviceCollection.AddSingleton <ISubscriber>(c => redis.GetSubscriber()); serviceCollection.AddSingleton <IMessageBus, RedisMessageBus>(); serviceCollection.AddSingleton <ICacheBase, RedisMessageCacheManager>(); } }
public RedisCacheManager(/*ICacheManager perRequestCacheManager,*/ IRedisConnectionWrapper connectionWrapper, GrandConfig config) { if (string.IsNullOrEmpty(config.RedisCachingConnectionString)) throw new Exception("Redis connection string is empty"); this._connectionWrapper = connectionWrapper; this._db = _connectionWrapper.GetDatabase(); }
public RedisCacheManager(GrandConfig config, IRedisConnectionWrapper connectionWrapper) { if (String.IsNullOrEmpty(config.RedisCachingConnectionString)) { throw new Exception("Redis connection string is empty"); } // ConnectionMultiplexer.Connect should only be called once and shared between callers this._connectionWrapper = connectionWrapper; this._db = _connectionWrapper.Database(); }
private void RegisterCache(ContainerBuilder builder, GrandConfig config) { builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().SingleInstance(); if (config.RedisPubSubEnabled) { var redis = ConnectionMultiplexer.Connect(config.RedisPubSubConnectionString); builder.Register(c => redis.GetSubscriber()).As <ISubscriber>().SingleInstance(); builder.RegisterType <RedisMessageBus>().As <IMessageBus>().SingleInstance(); builder.RegisterType <RedisMessageCacheManager>().As <ICacheManager>().SingleInstance(); } }
private void RegisterMachineNameProvider(ContainerBuilder builder, GrandConfig config) { if (config.RunOnAzureWebApps) { builder.RegisterType <AzureWebAppsMachineNameProvider>().As <IMachineNameProvider>().SingleInstance(); } else { builder.RegisterType <DefaultMachineNameProvider>().As <IMachineNameProvider>().SingleInstance(); } }
/// <summary> /// Add and configure any of the middleware /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { var config = new GrandConfig(); configuration.GetSection("Grand").Bind(config); //add data protection services.AddGrandDataProtection(config); //add authentication services.AddGrandAuthentication(configuration); }