Re:.NET 5.0
by nightski on Tuesday November 10, 2020 @12:28PM
(#25048481)
Do you type every line typically? If you use Rider or VS pretty much every one of those lines can be auto generated with autocomplete. Also, this can easily be worked around. Just create a Singleton which has the settings injected into it. I prefer the testability of the injected version but if you'd rather access a static global it is very easy to do.
[ Parent
| on HN ]
I do agree
I just type IOptions<T> config in ctor, use ctrl+. and private readonly property and it's initialization is generated
Re:.NET 5.0
by mattmanser on Tuesday November 10, 2020 @12:44PM
(#25048676)
That doesn't work unless you already have the using statements, which you won't have as you haven't added it yet.
I just tried it.
I'm using Roslynator:
https://i.imgur.com/cWs1M77.png
and I have some naming rule
https://i.imgur.com/iPwNj5b.png
So I basically have to type IOptions<T> Name and use ctrl+. twice in order to generate private readonly property and initialize it and add using to IOptions
you can use property injection when you use something like autofac as the di container.
Re:.NET 5.0
by FridgeSeal on Tuesday November 10, 2020 @05:19PM
(#25052822)
Cool, so I'll add another dependency and figure out how to use that, to save myself time having to write out MS's convoluted dependency-injected configuration code.
Meanwhile one could of have this solved in their projects in less than the time it took to have this HN discussion and moved on with their life. Seriously, somethings are worth complaining over, others are not.
well you don't need to use dependency injection at all. there. is no need to use IConfiguration.
also as far as I heard, is that microsoft is working on a micro web framework, that does not use di. (something like https://github.com/featherhttp/framework, just more official i guess)