Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

asp.net core的HostingEnvironment问题,为什么不能解析这个服务?

image
image.png
这样写会有问题吗?为什么我core 2.2的项目可以使用,怎么用3.1就不行了?是我那里写错了吗?求大牛解答,谢谢了,很急!~~~~


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

第一,依赖注入时你应该用接口 IHostingEnvironment,而非具体的实现类 HostingEnvironment

第二,即便是接口,也已经在 .NET 3.x 中被标记为了废弃,取而代之的是 IHostEnvironment

P.S. 建议仔细阅读升级指南,无论是 MSDN 官方文档、还是中文网络上,都有大把的 .NET Core 2.x 怎么升级到 .NET 3.x 的注意事项。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...