예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // injects IOptionsMonitor<ValuesConfiguration>)
            services.Configure <APIConfiguration>(Configuration.GetSection(APIConfiguration.Position));
            APISecret _secret = new APISecret();

            try
            {
                //using (var reader = new StreamReader(@"secrets\App-Secret.txt"))
                using (var reader = new StreamReader(@"secrets/App-Secret"))
                {
                    _secret.Secret = reader.ReadToEnd();
                }
                if (string.IsNullOrEmpty(_secret.Secret))
                {
                    _secret.Secret = "data missing";
                }
            }
            catch (Exception ex)
            {
                _secret.Secret = ex.Message;
            }

            // injects ValuesConfiguration
            APIConfiguration apiConfiguration = new APIConfiguration();

            Configuration.GetSection(APIConfiguration.Position).Bind(apiConfiguration);
            services.AddSingleton <APIConfiguration>(apiConfiguration);
            services.AddSingleton <APISecret>(_secret);
            services.AddControllers();
            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen();
        }
 public ConfigReaderController(ILogger <ConfigReaderController> logger, IOptionsMonitor <APIConfiguration> apiMonitoredConfiguration, APIConfiguration apiConfiguration, APISecret secrets)
 {
     _logger = logger;
     _valuesMonitoredConfiguration = apiMonitoredConfiguration;
     _valuesConfiguration          = apiConfiguration;
     _secrets = secrets;
 }