Read and use settings from appsettings.json without IOptions?

后端 未结 2 1100
攒了一身酷
攒了一身酷 2020-12-11 20:40

.NET Core allows to lazily read settings from configuration file, de-serialize it to a POCO and register that POCO in built-in DI container with one line of code:

         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-11 21:39

    You can just mock IOptions if you want to unit test services that depend on it. See this question and its answers. Depending on IOptions is still just depending on an interface, so it's not (or shouldn't be) making your code harder to test.

提交回复
热议问题