/// <summary>
        /// Add services to the application and configure service provider
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration of the application</param>
        /// <returns>Configured service provider</returns>
        public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration)
        {
            //add NopConfig configuration parameters
            services.ConfigureStartupConfig <NopConfig>(configuration.GetSection("Nop"));
            //add hosting configuration parameters
            services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting"));
            //add accessor to HttpContext
            services.AddHttpContextAccessor();

            //create, initialize and configure the engine
            var engine = EngineContext.Create();

            engine.Initialize(services);
            var serviceProvider = engine.ConfigureServices(services, configuration);

            if (DataSettingsManager.DatabaseIsInstalled)
            {
                //implement schedule tasks
                //database is already installed, so start scheduled tasks
                TaskManager.Instance.Initialize();
                TaskManager.Instance.Start();

                //log application start
                EngineContext.Current.Resolve <ILogger>().Information("Application started", null, null);

                IConfigurationDbContext context = EngineContext.Current.Resolve <IConfigurationDbContext>();
                context.CheckConflict();
                context.AddTemporal();
                context.AddChangeTracking(EngineContext.Current.Resolve <NopConfig>());
            }

            return(serviceProvider);
        }
Esempio n. 2
0
        /// <summary>
        /// Install data
        /// </summary>
        /// <param name="defaultUserEmail">Default user email</param>
        /// <param name="defaultUserPassword">Default user password</param>
        /// <param name="installSampleData">A value indicating whether to install sample data</param>
        public virtual void InstallData(string defaultUserEmail,
                                        string defaultUserPassword, bool installSampleData = true)
        {
            _configurationDbContext.AddTemporal();
            _configurationDbContext.AddChangeTracking(_nopConfig);
            ExecuteSqlFile(_fileProvider.MapPath(NopInstallationDefaults.RequiredDataPath));
            InstallLocaleResources();
            UpdateDefaultUser(defaultUserEmail, defaultUserPassword);

            if (installSampleData)
            {
                ExecuteSqlFile(_fileProvider.MapPath(NopInstallationDefaults.SampleDataPath));
            }
        }