Mironline
Mironline

Reputation: 2799

Inject Interface to Overloaded Class Constructor Using StructureMap

I'm using StructureMap in ASP .Net MVC 4 and I have got the following Interface and implemented class in my project infrastructure :

public interface IUnitOfWork
{
    void Commit();
}

public class UnitOfWork : IUnitOfWork
{
    public void Commit()
    {
        // Track all changes in database
    }
}

My HomeController is used the IUnitOfWork interface as constructor parameter :

public class HomeController
{
    IUnitOfwork unitOfWork;

    public HomeController(IUnitOfwork unitOfWork)
    {
        this.unitOfWork = unitOfWork;
    }
 }

How can I inject IUniOfWork interface to overloaded HomeController class as parameter?

Upvotes: 3

Views: 393

Answers (1)

Mohsen Alikhani
Mohsen Alikhani

Reputation: 1666

You must perform the following steps:

  1. Remove and uninstall any configurations and packages for StructureMap.
  2. Install structurmap.mvc4 from nuget
  3. Configure your IoC container as :

    x.For(IUnitOfWork).Use(UnitOfWork)

Upvotes: 3

Related Questions