Beispiel #1
0
 public CoreRuntime(
     ILoggerFactory loggerFactory,
     IRuntimeState state,
     ComponentCollection components,
     IApplicationShutdownRegistry applicationShutdownRegistry,
     IProfilingLogger profilingLogger,
     IMainDom mainDom,
     IUmbracoDatabaseFactory databaseFactory,
     IEventAggregator eventAggregator,
     IHostingEnvironment hostingEnvironment,
     IUmbracoVersion umbracoVersion,
     IServiceProvider?serviceProvider)
     : this(
         state,
         loggerFactory,
         components,
         applicationShutdownRegistry,
         profilingLogger,
         mainDom,
         databaseFactory,
         eventAggregator,
         hostingEnvironment,
         umbracoVersion,
         serviceProvider,
         serviceProvider?.GetRequiredService <IHostApplicationLifetime>())
 {
 }
Beispiel #2
0
    /// <summary>
    ///     Initializes a new instance of the <see cref="CoreRuntime" /> class.
    /// </summary>
    public CoreRuntime(
        IRuntimeState state,
        ILoggerFactory loggerFactory,
        ComponentCollection components,
        IApplicationShutdownRegistry applicationShutdownRegistry,
        IProfilingLogger profilingLogger,
        IMainDom mainDom,
        IUmbracoDatabaseFactory databaseFactory,
        IEventAggregator eventAggregator,
        IHostingEnvironment hostingEnvironment,
        IUmbracoVersion umbracoVersion,
        IServiceProvider?serviceProvider,
        IHostApplicationLifetime?hostApplicationLifetime)
    {
        State = state;

        _loggerFactory = loggerFactory;
        _components    = components;
        _applicationShutdownRegistry = applicationShutdownRegistry;
        _profilingLogger             = profilingLogger;
        _mainDom                 = mainDom;
        _databaseFactory         = databaseFactory;
        _eventAggregator         = eventAggregator;
        _hostingEnvironment      = hostingEnvironment;
        _umbracoVersion          = umbracoVersion;
        _serviceProvider         = serviceProvider;
        _hostApplicationLifetime = hostApplicationLifetime;
        _logger = _loggerFactory.CreateLogger <CoreRuntime>();
    }
Beispiel #3
0
 public CoreRuntime(
     ILoggerFactory loggerFactory,
     IRuntimeState state,
     ComponentCollection components,
     IApplicationShutdownRegistry applicationShutdownRegistry,
     IProfilingLogger profilingLogger,
     IMainDom mainDom,
     IUmbracoDatabaseFactory databaseFactory,
     IEventAggregator eventAggregator,
     IHostingEnvironment hostingEnvironment,
     IUmbracoVersion umbracoVersion)
     : this(
         loggerFactory,
         state,
         components,
         applicationShutdownRegistry,
         profilingLogger,
         mainDom,
         databaseFactory,
         eventAggregator,
         hostingEnvironment,
         umbracoVersion,
         null)
 {
 }
Beispiel #4
0
        /// <summary>
        /// Creates an <see cref="IUmbracoBuilder"/> and registers basic Umbraco services
        /// </summary>
        public static IUmbracoBuilder AddUmbraco(
            this IServiceCollection services,
            IWebHostEnvironment webHostEnvironment,
            IConfiguration config)
        {
            if (services is null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (config is null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            IHostingEnvironment tempHostingEnvironment = GetTemporaryHostingEnvironment(webHostEnvironment, config);

            var loggingDir    = tempHostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.LogFiles);
            var loggingConfig = new LoggingConfiguration(loggingDir);

            services.AddLogger(tempHostingEnvironment, loggingConfig, config);

            // The DataDirectory is used to resolve database file paths (directly supported by SQL CE and manually replaced for LocalDB)
            AppDomain.CurrentDomain.SetData("DataDirectory", tempHostingEnvironment?.MapPathContentRoot(Constants.SystemDirectories.Data));

            // Manually create and register the HttpContextAccessor. In theory this should not be registered
            // again by the user but if that is the case it's not the end of the world since HttpContextAccessor
            // is just based on AsyncLocal, see https://github.com/dotnet/aspnetcore/blob/main/src/Http/Http/src/HttpContextAccessor.cs
            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            services.AddSingleton(httpContextAccessor);

            var requestCache = new HttpContextRequestAppCache(httpContextAccessor);
            var appCaches    = AppCaches.Create(requestCache);

            services.ConfigureOptions <ConfigureKestrelServerOptions>();
            services.ConfigureOptions <ConfigureIISServerOptions>();
            services.ConfigureOptions <ConfigureFormOptions>();

            IProfiler profiler = GetWebProfiler(config);

            ILoggerFactory loggerFactory = LoggerFactory.Create(cfg => cfg.AddSerilog(Log.Logger, false));

            TypeLoader typeLoader = services.AddTypeLoader(
                Assembly.GetEntryAssembly(),
                tempHostingEnvironment,
                loggerFactory,
                appCaches,
                config,
                profiler);

            // adds the umbraco startup filter which will call UseUmbraco early on before
            // other start filters are applied (depending on the ordering of IStartupFilters in DI).
            services.AddTransient <IStartupFilter, UmbracoApplicationServicesCapture>();

            return(new UmbracoBuilder(services, config, typeLoader, loggerFactory, profiler, appCaches, tempHostingEnvironment));
        }
    /// <summary>
    ///     Creates an <see cref="IUmbracoBuilder" /> and registers basic Umbraco services
    /// </summary>
    public static IUmbracoBuilder AddUmbraco(
        this IServiceCollection services,
        IWebHostEnvironment webHostEnvironment,
        IConfiguration config)
    {
        if (services is null)
        {
            throw new ArgumentNullException(nameof(services));
        }

        if (config is null)
        {
            throw new ArgumentNullException(nameof(config));
        }

        // Setup static application logging ASAP (e.g. during configure services).
        // Will log to SilentLogger until Serilog.Log.Logger is setup.
        StaticApplicationLogging.Initialize(new SerilogLoggerFactory());

        // The DataDirectory is used to resolve database file paths (directly supported by SQL CE and manually replaced for LocalDB)
        AppDomain.CurrentDomain.SetData(
            "DataDirectory",
            webHostEnvironment.MapPathContentRoot(Constants.SystemDirectories.Data));

        // Manually create and register the HttpContextAccessor. In theory this should not be registered
        // again by the user but if that is the case it's not the end of the world since HttpContextAccessor
        // is just based on AsyncLocal, see https://github.com/dotnet/aspnetcore/blob/main/src/Http/Http/src/HttpContextAccessor.cs
        IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

        services.AddSingleton(httpContextAccessor);

        var requestCache = new HttpContextRequestAppCache(httpContextAccessor);
        var appCaches    = AppCaches.Create(requestCache);

        services.ConfigureOptions <ConfigureKestrelServerOptions>();
        services.ConfigureOptions <ConfigureFormOptions>();

        IProfiler profiler = GetWebProfiler(config);

        services.AddLogger(webHostEnvironment, config);

        ILoggerFactory loggerFactory = new SerilogLoggerFactory();

        TypeLoader typeLoader = services.AddTypeLoader(Assembly.GetEntryAssembly(), loggerFactory, config);

        IHostingEnvironment tempHostingEnvironment = GetTemporaryHostingEnvironment(webHostEnvironment, config);

        return(new UmbracoBuilder(services, config, typeLoader, loggerFactory, profiler, appCaches, tempHostingEnvironment));
    }
 public static ILoggingConfiguration GetLoggingConfiguration(IHostingEnvironment hostingEnv) => s_testHelperInternal.GetLoggingConfiguration(hostingEnv);