選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

StartupConfiguration.cs 950B

1234567891011121314151617181920212223242526272829
  1. using Microsoft.Extensions.Configuration;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using System;
  4. namespace MVCTemplate.Business.Infrastructure
  5. {
  6. public class StartupConfiguration
  7. {
  8. public static TConfig ConfigureStartupConfig<TConfig>(IServiceCollection services, IConfiguration configuration) where TConfig : class, new()
  9. {
  10. if (services == null)
  11. throw new ArgumentNullException(nameof(services));
  12. if (configuration == null)
  13. throw new ArgumentNullException(nameof(configuration));
  14. //create instance of config
  15. var config = new TConfig();
  16. var classType = typeof(TConfig);
  17. //bind it to the appropriate section of configuration
  18. configuration.Bind(classType.Name, config);
  19. //and register it as a service
  20. services.AddSingleton(config);
  21. return config;
  22. }
  23. }
  24. }