WhiskerBiscuit
WhiskerBiscuit

Reputation: 5157

Why use Ninject or other IoC container with the repository pattern?

I'm trying to build an app in MVC using TDD and using the repository pattern and a Unit of Work

In my tests I create a mock Unit of Work (which has mock repositories), and pass that in to my controller. Since my controller's default constructor will create it's own instance of the UoW (and the embedded repositories), how could I benefit from using an IoC?

Am I not "injecting" a UoW already using my test?

   private IUnitOfWork uow;

   public AccountController(IUnitOfWork unitOfWork)
        : this(unitOfWork)
    {
    }

    public AccountController()
        : this(new UnitOfWork())
    {

    }

Upvotes: 0

Views: 190

Answers (1)

Maarten
Maarten

Reputation: 22945

Correct. You should remove the extra controller.

Some people think you should always have just a single constructor in injected services, and I agree. It keeps it simple, and dependencies shouldn't be optional.

Upvotes: 1

Related Questions