Do we need interfaces for dependency injection?

后端 未结 4 474
青春惊慌失措
青春惊慌失措 2020-12-14 06:29

I have an ASP.NET Core application. The application has few helper classes that does some work. Each class has different signature method. I see lot of .net core examples on

4条回答
  •  [愿得一人]
    2020-12-14 07:07

    Does it work? Yes. Should you do it? No.

    Dependency Injection is a tool for the principle of Dependency Inversion : https://en.wikipedia.org/wiki/Dependency_inversion_principle

    Or as it's described in SOLID

    one should “depend upon abstractions, [not] concretions."

    You can just inject concrete classes all over the place and it will work. But it's not what DI was designed to achieve.

提交回复
热议问题