asp.net mvc 3 - custom membership provider and unity dependency injection -


i have found few questions similar 1 i'm posting i'm not getting them need. i'm still struggling implement custommembershipprovider using microsoft unity di.

custom membership:

public class custommembershipproviderservice : membershipprovider     {         private readonly iuserservice _userservice;          public custommembershipproviderservice(iuserservice userservice)         {             this._userservice = userservice;         }          public override string applicationname         {         ... 

user service:

public class userservice : iuserservice     {         private readonly iuserrepository _repository;         private readonly iunitofwork _unitofwork;         public userservice(iuserrepository repository, iunitofwork unitofwork)         {             this._repository = repository;             this._unitofwork = unitofwork;         }         ... 

accountcontroller:

public class accountcontroller : controller {      // next line don't feel sure do?      // shouldn't controller constructor use interface property?       private readonly custommembershipproviderservice _custommembershipproviderservice;       public accountcontroller(custommembershipproviderservice custommembershipproviderservice)      {          this._custommembershipproviderservice = custommembershipproviderservice;      }      ... 

how can create interface membershipprovider class?

i've tried:

public interface icustommembershipprovider : membershipprovider 

but don't think works, i'm stuck, , don't know how implement membershipprovider using repositories, uow, services, , unity di

answer second question

the issue membershipprovider , roleprovider not built container, framework. afaik way set active membership provider web.config file. so, if want use container resolve dependencies repositories, services etc. via container, have use old (i'm kidding) service locator pattern.

public class custommebershipprovider : icustommebershipprovider  {    public bool validateuser(string user, string pwd) {      var svc = global.container.resolve<imyservice>();      /* ... */    } } 

to first question

you can still inject active membership provider in controllers using constructor injection. first of all, create interface methods need. issue here membershipprovider concrete class, can't inherit interface it. create new interface, copying method signatures of function need membershipprovider:

public interface icustommembershipprovider {     bool mymethod();       /* membershipprovider */     bool validateuser(string username,  string password);     /* ... */ } 

then let provider implement , inject:

container   .registertype<icustommembershipprovider>(      new injectionfactory(c => (icustommembershipprovider) membership.provider)) 

of course, still have register custom membership provider in web.config.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -