示例#1
0
        /// <summary>
        /// Adds components of the info actuator to Microsoft-DI
        /// </summary>
        /// <param name="services">Service collection to add info to</param>
        /// <param name="config">Application configuration (this actuator looks for a settings starting with management:endpoints:info)</param>
        /// <param name="contributors">Contributors to application information</param>
        public static void AddInfoActuator(this IServiceCollection services, IConfiguration config, params IInfoContributor[] contributors)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            services.TryAddSingleton <IInfoOptions>(options);
            services.RegisterEndpointOptions(options);
            AddContributors(services, contributors);
            services.TryAddSingleton <InfoEndpoint>();
        }
示例#2
0
        /// <summary>
        /// Adds components of the info actuator to Microsoft-DI
        /// </summary>
        /// <param name="services">Service collection to add info to</param>
        /// <param name="config">Application configuration. Retrieved from the <see cref="IServiceCollection"/> if not provided (this actuator looks for a settings starting with management:endpoints:info)</param>
        /// <param name="contributors">Contributors to application information</param>
        public static void AddInfoActuator(this IServiceCollection services, IConfiguration config = null, params IInfoContributor[] contributors)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

            services.AddActuatorManagementOptions(config);

            var options = new InfoEndpointOptions(config);

            services.TryAddSingleton <IInfoOptions>(options);
            services.RegisterEndpointOptions(options);
            AddContributors(services, contributors);
            services.TryAddSingleton <InfoEndpoint>();
        }