Beispiel #1
0
        /// <summary>
        /// dependency injection container of .NET Core
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.Configure <ServiceInformationMapper>(Configuration.GetSection("ServiceInformation"));

            //Example of IoC in .NET Core
            services.AddScoped <ITestService, TestService>();

            //Example of Get value of ServiceInformationMapper in ConfigureService
            ServiceInformationMapper serviceInformation = new ServiceInformationMapper();

            Configuration.GetSection("ServiceInformation").Bind(serviceInformation);
        }
 public HomeController(IConfiguration configuration, IOptions <ServiceInformationMapper> serviceInformationMapper, ITestService testService)
 {
     _configuration            = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _serviceInformationMapper = serviceInformationMapper.Value ?? throw new ArgumentNullException(nameof(serviceInformationMapper));
     _testService = testService ?? throw new ArgumentNullException(nameof(testService));
 }