Esempio n. 1
0
        /// <summary>
        /// HACK: returns an AspNetCoreHostingEnvironment that doesn't monitor changes to configuration.<br/>
        /// We require this to create a TypeLoader during ConfigureServices.<br/>
        /// Instances returned from this method shouldn't be registered in the service collection.
        /// </summary>
        private static IHostingEnvironment GetTemporaryHostingEnvironment(IWebHostEnvironment webHostEnvironment, IConfiguration config)
        {
            var hostingSettings        = config.GetSection(Cms.Core.Constants.Configuration.ConfigHosting).Get <HostingSettings>() ?? new HostingSettings();
            var wrappedHostingSettings = new OptionsMonitorAdapter <HostingSettings>(hostingSettings);

            var webRoutingSettings        = config.GetSection(Cms.Core.Constants.Configuration.ConfigWebRouting).Get <WebRoutingSettings>() ?? new WebRoutingSettings();
            var wrappedWebRoutingSettings = new OptionsMonitorAdapter <WebRoutingSettings>(webRoutingSettings);

            return(new AspNetCoreHostingEnvironment(
                       wrappedHostingSettings,
                       wrappedWebRoutingSettings,
                       webHostEnvironment));
        }
Esempio n. 2
0
        /// <summary>
        /// HACK: returns an AspNetCoreHostingEnvironment that doesn't monitor changes to configuration.<br/>
        /// We require this to create a TypeLoader during ConfigureServices.<br/>
        /// Instances returned from this method shouldn't be registered in the service collection.
        /// </summary>
        private static IHostingEnvironment GetTemporaryHostingEnvironment(IWebHostEnvironment webHostEnvironment, IConfiguration config)
        {
            var hostingSettings           = config.GetSection(Cms.Core.Constants.Configuration.ConfigHosting).Get <HostingSettings>() ?? new HostingSettings();
            var webRoutingSettings        = config.GetSection(Cms.Core.Constants.Configuration.ConfigWebRouting).Get <WebRoutingSettings>() ?? new WebRoutingSettings();
            var wrappedHostingSettings    = new OptionsMonitorAdapter <HostingSettings>(hostingSettings);
            var wrappedWebRoutingSettings = new OptionsMonitorAdapter <WebRoutingSettings>(webRoutingSettings);

            // This is needed in order to create a unique Application Id
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddDataProtection();
            serviceCollection.AddSingleton <IHostEnvironment>(s => webHostEnvironment);
            var serviceProvider = serviceCollection.BuildServiceProvider();

            return(new AspNetCoreHostingEnvironment(
                       serviceProvider,
                       wrappedHostingSettings,
                       wrappedWebRoutingSettings,
                       webHostEnvironment));
        }