Mocking an IoC Container?

前端 未结 2 1877
心在旅途
心在旅途 2021-01-15 03:52

Does it make sense to mock an IoC container? If so how would I go about it, using Moq?

I am creating a Prism 4 app, using Unity 2.0 as the IoC container. I inject th

2条回答
  •  终归单人心
    2021-01-15 04:26

    No, it doesn't make sense to mock a DI container because application classes should not reference a container at all.

    Instead of injecting the container into the classes, you should inject only the services that they need. This will also mean that you can unit test them without referencing a DI container at all.

提交回复
热议问题