c# - I can't add ApplicationRoleManager to startup.auth -


the question pretty simple, i'm trying implement roles application, , if not places go to, tell me use following line in startup.auth:

 app.createperowincontext<applicationrolemanager>(applicationrolemanager.create); 

the problem is, visual studio keeps telling me applicationrolemanager doesn't exist! searched different ways maybe implement this, keeps saying "use applicationrolemanager", can't use , apparently, got libraries needed too.

any welcome here.

apparently, application didn't auto-generate applicationrolemanager code, i'm trying add manually. in identityconfig.cs have added following code:

public class applicationrolemanager : rolemanager<identityrole> {     public applicationrolemanager(irolestore<identityrole, string> rolestore)         : base(rolestore)     {     } } 

at point i'm stuck, because apparently need other methods (like create method) make work, cannot find example of code add.

edit trying implement factory implement role management. i'm having problems vs not detecting objects, here's picture show off better:

capture

i have updated identity packages in nuget, i'm still having problems libraries.

you creating factory create role manager. create method method should implement. honest don't need either if don't want. there 2 ways of doing this:

app.createperowincontext<rolemanager<identityrole>>(new rolemanager<identityrole>(new rolestore<identityrole, string>(new somecontext())); 

or can create factory you:

public class rolemanagerfactory {     private readonly idbcontextfactory<somecontext> contextfactory     public rolemanagerfactory(idbcontextfactory<somecontext> contextfactory)     {          this.contextfactory = contextfactory;     }      public rolemanager<identityrole> create()     {         return new rolemanager<identityrole>(new rolestore<identityrole, string>(contextfactory.create()));     }      // if have instantiated context use, can pass in here     public rolemanager<identityrole> create(somecontext context)     {         return new rolemanager<identityrole>(new rolestore<identityrole, string>(context));     } }  var factory = new rolemanagerfactory(); app.createperowincontext<rolemanager<identityrole>>(factory.create()); 

i believe these ways easier trying do.

edit

i added context factory in, because remembered need pass context role store. entityframework idbcontextfactory<tcontext> interface, need create concrete implementation , implement interface, create method return new context: new somecontext().

this in apps. in fact use dependency injection , make role manager created per request. use factory can inject role manager classes:

public interface irolemanagerfactory {     rolemanager<identityrole> create(); } 

so in classes can this:

public class rolecontroller : controller {     private readonly irolemanagerfactory rolemanagerfactory;      public rolecontroller (irolemanagerfactory rolemanagerfactory)     {          this.rolemanagerfactory = rolemanagerfactory;     }      // create method     public async task<jsonresult> createrole(string role)     {         using (var rolemanager = this.rolemanagerfactory.create())         {             var result = await rolemanager.createasync(role);              return json(new { succeeded: result.succeeded });         }     } } 

edit

i have updated example correct usage of role manager , db context.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -