带有DI的.NET Core的静态类或单尔顿的静态类别
我正在将公用事业类迁移到.NET核心类库。
起初,我以为我可以简单地为此组成一个静态课程,但是我对 iConfiguration 有一个依赖性,所以我不确定如何继续这样做。
这种情况的最佳实践是什么?
我应该使用 class 并使用构造器注入,然后将其添加到配置中?
我应该使用静态类并使用方法注入吗?
或者我什至不应该遇到此类问题: - ?
我想第一个版本更好。
抱歉,如果这是一个愚蠢的问题,我对自己的选择有些困惑。
谢谢你!
I'm migrating a utility class to a .NET Core class library.
At first I thought I can simply make a static class for this but I have a dependency on IConfiguration so I'm not sure how to proceed with this.
What is the best practice for this situation?
Should I use a class and use constructor injection and then add it in ConfigureServices?
Should I use a static class and use method injection?
Or I shouldn't even come across this type of issue :-?
I would guess that the first version is nicer.
Sorry if this is a dumb question, I'm a bit confused for the options I have.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论