Improve the performance of configuration binding · Issue #36130 · dotnet/runtime (original) (raw)

I have a configuration class which contains over 50 properties. I want to get the new configuration for each request so IOptionsSnapshot is my choice, but the problem is that configuration is using Reflection to bind the options for each request. And for obvious reasons it can't be cached like IOptions or IOptionsMonitor.

Also breaking the configuration class to multiple class is not an option here.

Describe the solution you'd like

Is it good idea to create a method using ILGenerator at runtime and use that to bind the configuration class? I assume once the method is created it has better performance than reflection.

P.S. I'm willing to create a PR for this.