In my ASP.NET Core application configuration usually doesn't change. So I want to create a typed Options object in ConfigureServices(IServiceCollection services)
and add that object as a singleton to the services using services.AddSingleton(typeof(IOptions), configuration.Get<Options>())
.
But ASP.NET Core doesn't allow to add additional parameters to the ConfigureServices(IServiceCollection services)
method.
So the following isn't possible:
public interface IOptions { ... }
public class Options : IOptions { ... }
...
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services
.AddSingleton(typeof(IOptions), configuration.Get<Options>())
.AddControllers();
}
Is there a way to achieve this (i.e. adding an Option object, configured by ASP.NET configuration services, to the services collection)?