0

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

Steven
  • 166,672
  • 24
  • 332
  • 435
Snehal
  • 329
  • 3
  • 14

1 Answers1

2

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: Property Injection into an Action Filter

Community
  • 1
  • 1
Joshua Flanagan
  • 8,527
  • 2
  • 31
  • 40