using DI to load repository instance on each mvc request

前端 未结 3 884
别那么骄傲
别那么骄傲 2021-01-13 13:16

I read on this post that they are using dependency injection to load repository instance on each mvc request.

I\'m not sure if I understand correctly but I currentl

3条回答
  •  再見小時候
    2021-01-13 13:42

    The main advantage of interfaces is that they encourage abstraction. If you want to mock a completely different implementation (for example, when performing unit testing, which you should be doing anyway :), you would just inject another implementation of the IUserRepository to your UserController constructor. This is, how I see it, one of the main advantages of using interfaces.

提交回复
热议问题