In my ASP.NET Core 3.1 application, I want to do some settings AT THE END since they are dependent on some other services being registered in the Startup.cs only. Can someone help me to understand why my class implementing the IPostConfigureOptions<T> is never invoked by .NET Core?
I have an Options class like this:
public class MyTestOptions
{
public string TestTest { get; set; }
}
This is used in the Startup.cs's ConfigureServices method as usual.
services.Configure<MyTestOptions>(o => { o.TestTest = "Test Test Test"; });
I need to change some settings "at the end". So, I implement IPostConfigureOptions<T> interface. The implementation class looks like this. (PostConfigure method not shown in the snippet below).
public class MyTestPostConfigure : IPostConfigureOptions<MyTestOptions>
This is then registered in the Startup.cs's ConfigureServices method as shown below.
services.ConfigureOptions<MyTestPostConfigure>();
I tried to register PostConfig class in different way too.
services.AddSingleton<IPostConfigureOptions<MyTestOptions>, MyTestPostConfigure>();
However, in any case the PostConfigure is not called.
Am I missing something?
**
- Why the PostConfigure is never executed?
- Isn't it true that all IPostConfigureOptions get executed automatically during startup? Or is there any case when .NET Core chooses not to run it until it's actually required?**