3 ms·
Yeah, the DI stuff is a lot, but eventually bringing in the dependencies becomes total autopilot. > I've given up with the config DI and just assign them all t
by asdfman123 6y ago
Yeah, the DI stuff is a lot, but eventually bringing in the dependencies becomes total autopilot.
> I've given up with the config DI and just assign them all to static variables.
Not to be a fanboy, but it's designed in a way where you CAN use all the fancy features. If you want something simpler, you can just do exactly what you did.
This syntax is probably wrong because I'm doing this from memory, you should probably also use the Lazy class or something, and if I were to actually write this code I'd think twice about thread safety -- but if you want simple static access to config values, you can just do this:
public static MyConfigPoco MyConfig {get;set;} = JsonConvert.DeserializeObject<MyConfigPoco>(File.ReadAllLines("appsettings.json")) ;