예제 #1
0
        /// <summary>
        /// Adds components of the Env actuator to Microsoft-DI
        /// </summary>
        /// <param name="services">Service collection to add actuator to</param>
        /// <param name="config">Application configuration (this actuator looks for settings starting with management:endpoints:dump)</param>
        public static void AddEnvActuator(this IServiceCollection services, IConfiguration config)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

            services.TryAddSingleton <IHostingEnvironment>((provider) =>
            {
                var service = provider.GetRequiredService <Microsoft.AspNetCore.Hosting.IHostingEnvironment>();
                return(new GenericHostingEnvironment()
                {
                    EnvironmentName = service.EnvironmentName,
                    ApplicationName = service.ApplicationName,
                    ContentRootFileProvider = service.ContentRootFileProvider,
                    ContentRootPath = service.ContentRootPath
                });
            });

            services.TryAddEnumerable(ServiceDescriptor.Singleton <IManagementOptions>(new ActuatorManagementOptions(config)));
            var options = new EnvEndpointOptions(config);

            services.TryAddSingleton <IEnvOptions>(options);
            services.RegisterEndpointOptions(options);
            services.TryAddSingleton <EnvEndpoint>();
        }
예제 #2
0
        /// <summary>
        /// Adds components of the Env actuator to Microsoft-DI
        /// </summary>
        /// <param name="services">Service collection to add actuator to</param>
        /// <param name="config">Application configuration. Retrieved from the <see cref="IServiceCollection"/> if not provided (this actuator looks for settings starting with management:endpoints:env)</param>
        public static void AddEnvActuator(this IServiceCollection services, IConfiguration config = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            config ??= services.BuildServiceProvider().GetService <IConfiguration>();
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            services.TryAddSingleton <IHostEnvironment>((provider) =>
            {
                var service = provider.GetRequiredService <IHostEnvironment>();
                return(new GenericHostingEnvironment()
                {
                    EnvironmentName = service.EnvironmentName,
                    ApplicationName = service.ApplicationName,
                    ContentRootFileProvider = service.ContentRootFileProvider,
                    ContentRootPath = service.ContentRootPath
                });
            });

            services.AddActuatorManagementOptions(config);
            var options = new EnvEndpointOptions(config);

            services.TryAddSingleton <IEnvOptions>(options);
            services.RegisterEndpointOptions(options);
            services.TryAddSingleton <EnvEndpoint>();
        }