views:

15

answers:

1

How to do Dependency Injection on Property of a class Using Structure Map

public class ContactController : Controller
{
    public IContactService Service { get; set; }

    public ContactController()
        : this(null,null)
    {
    }

    [SetterProperty]
    public MembershipProvider Provider { get; private set; }
}

Here when i Create instance of ContactController i want provider to be set to Mock<MembershipProvider> please help me how to go about doing this? Mock is Moq Framework class

+1  A: 

If you are using a Mock, you are most likely writing test code. If thats the case, you likely don't need a dependency injection tool like StructureMap involved. Just set the Provider property manually to your MembershpProvider in your test setup code.

controller.Provider = Mock<MembershipProvider>

If you really want to configure setter injection using StructureMap, see this answer: http://stackoverflow.com/questions/3876436/property-injection-into-an-action-filter/3877567#3877567

Joshua Flanagan