Access configuration through dependency injection in .NET Core console application
问题 How do I properly Activate a configuration that was added using the ServiceCollection.Configure function ? public static void Main(args[] args) { serviceCollection = new ServiceCollection(); serviceCollection .Configure<MyOptions>(Configuration.GetSection("options")); Services = serviceCollection.BuildServiceProvider(); ActivatorUtilities.CreateInstance<MyOptions>(Services); ActivatorUtilities.CreateInstance<SomeClassThatNeedsoptions>(Services); } public SomeClassThatNeedsoptions(IOptions