Using appSettings custom properties in controller partials

Is there any example code out there on how we can pass custom properties from the appSettings files into our controllers?

I've done a Startup.Custom.cs that hooks into the onConfigureServices method to grab the values and put them on the services.Configure:

    partial void OnConfigureServices(IServiceCollection services)
        var appSettings = Configuration.GetSection("MyConfig");

Unfortunately, the only way I know how to then hook into that dependency IOptions is in the constructor method, which we cannot override using a Custom class to hook into the partials. For example, I'd like to use the config values in a "OnTableItemCreated" partial.


Hi @gabe,

You can try one of the following:

  1. Add a new constructor with the required parameter and make it invoke the generated one via this(...)
  2. Use runtime dependency injection.

The second is guaranteed to work. Haven't tested the first but is definitely cleaner (if it works).

Thanks korchev.. unfortunately, I wasn't able to get either to work. Using your second option, the GetService value was always null)

As a poor workaround, I setup a static variable on Startup.Custom.cs and assigned the config object to it and can then reference that directly in the Controllers.

@gabe We use the second method above to access dbcontext and configuration from radzen generated classes.
This is an example on the generated data context class .custom.cs