Пример #1
0
        /// <summary>
        /// Extension method to add services into the <see cref="IServiceCollection"/>
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IServiceCollection AddCalculatePiServices(this IServiceCollection services, IConfiguration configuration)
        {
            IConfigurationSection configurationSection = configuration.GetSection(PiConfiguration.SECTIONNAME);
            PiConfiguration       settings             = configurationSection.Get <PiConfiguration>();

            if (settings is null)
            {
                throw new CalculatePiServiceException($"Configuration section named {PiConfiguration.SECTIONNAME} could not be serialized into type {typeof(PiConfiguration)}.  Please check the spelling of the configuration section name.");
            }
            services.AddSingleton(resolver => settings);
            services.AddTransient <ICalculatePiService, CalculatePiService>();

            return(services);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="piConfiguration"></param>
 public CalculatePiService(ILogger <CalculatePiService> logger, PiConfiguration piConfiguration)
 {
     _logger = logger;
     _logger.LogInformation("CalculatePiService - Ctor Called");
     _piConfiguration = piConfiguration;
 }