none
请问.net core 的依赖注入功能有正规的文档说明吗? RRS feed

全部回复

  • 你好,

    你可以参照微软官方文档里面对依赖注入的解释以及代码案例。

    链接:

    https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-3.0 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年11月26日 5:13
  • 非常感谢
    2019年11月26日 7:23
  • 微软的帮助为了说明问题,就不能写点简单的用法吗,非要弄得高深莫测似的,才能显示自己水平?
    2019年11月26日 7:36
  • 你好,

    其实依赖注入在ASP.NET Core中使用还是非常简单的, 只需要在Startup.cs里面注册下,然后再在controller里面使用就行了。注入过程都由ASP.NET Core帮你做好了。

    比如在MVC中使用的话,直接如下代码:

    public class MoviesController : Controller
    {
        private readonly MvcMovieContext _context;
    
        public MoviesController(MvcMovieContext context)
        {
            _context = context;
        }


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年11月27日 6:52
  • 好的,谢谢
    2019年11月30日 3:07