我正在我的项目中实现依赖注入。我遇到了两种添加单例服务的方法-
services.AddSingleton(new MyCustomService())
和
services.AddSingleton<MyCustomService>()
两种方法似乎都有效。这两种方法有什么区别,应该使用哪种方法?
MyCustomService
AddSingleton<TService>(IServiceCollection)