我正在我的项目中实现依赖注入。我遇到过两种添加单例服务的方法 -
services.AddSingleton(new MyCustomService())
和
services.AddSingleton<MyCustomService>()
两种方法似乎都有效。这两种方法有什么区别,我应该使用哪一种?
c# dependency-injection .net-core asp.net-core
.net-core ×1
asp.net-core ×1
c# ×1
dependency-injection ×1