2

I'm having problems to implement CodeFirstMembership provider using a unitofwork pattern.

When I tried to inject unitofwork to the constructor of custom MemberShipProvider class, always received the error: "No parameterless constructor defined for this object."

This is the code:

    public class CodeFirstMembershipProvider : MembershipProvider
    {
        private readonly IUnitOfWork unitOfWork;

        public CodeFirstMembershipProvider(IUnitOfWork unitOfWork)
        {
            this.unitOfWork = unitOfWork;
        }

And this is webconfig section:

      <membership defaultProvider="CodeFirstMembershipProvider">
          <providers>
              <add name="CodeFirstMembershipProvider" type="Pacific.WebUI.CustomMembership.CodeFirstMembershipProvider" connectionStringName="DataContext" />
          </providers>
      </membership>

The problem is, "not sure", the default implementation of MemberShipProvider is a constructor without parameters and I don't know how to inject my unitofwork class into this provider class.

Could anybody help me?

tereško
  • 58,060
  • 25
  • 98
  • 150
Jose
  • 95
  • 7

1 Answers1

0

Yeah I've tried to do this in the past, and it can't be done using the configuration option you have above.

You could create a Property that get's set after the Membership provider has been created.

You could also create and set your Membership provider in code, rather than relying on the configuration to create and build your provider.

Khalid Abuhakmeh
  • 10,709
  • 10
  • 52
  • 75