c# - How does IdentityFactoryOptions<AppIdentityUserManager> options get set? -


if you've worked identity 2.0, you've seen piece of code:

       public static appidentityusermanager create(             identityfactoryoptions<appidentityusermanager> options,             iowincontext context)         {            [snip]             var dataprotectionprovider = options.dataprotectionprovider;              if (dataprotectionprovider != null)             {                 manager.usertokenprovider =                     new dataprotectortokenprovider<appidentityuser>(                         dataprotectionprovider.create("asp.net identity"));             }             return manager;         } 

i understand that. in application options.dataprotectionprovider (obviously passed in parameter) null. how , set (or not case may be?) every place i've looked has exact snippet of code, no explanation setting dataprotectionprovider.

edit: read dataprotectionprovider in identity sample project, explains usertokenprovider not explain how set in identityfactoryoptions object.

it's set when user manager created.

if you're using createperowincontext method inside owin startup class, extension defined in microsoft.aspnet.identity.owin, extension creates new identityfactoryoption object , passes func parameter of createperowincontext.

you can see details of createperowincontext in the source code here.

public static iappbuilder createperowincontext<t>(this iappbuilder app,     func<identityfactoryoptions<t>, iowincontext, t> createcallback,     action<identityfactoryoptions<t>, t> disposecallback) t : class, idisposable {     if (app == null)     {         throw new argumentnullexception("app");     }     if (createcallback == null)     {         throw new argumentnullexception("createcallback");     }     if (disposecallback == null)     {         throw new argumentnullexception("disposecallback");     }      app.use(typeof (identityfactorymiddleware<t, identityfactoryoptions<t>>),         new identityfactoryoptions<t>         {             dataprotectionprovider = app.getdataprotectionprovider(),             provider = new identityfactoryprovider<t>             {                 oncreate = createcallback,                 ondispose = disposecallback             }         });     return app; } 

note if have own di mechanism in app, don't need use createperowincontext approach , wire creation of objects yourself. way you'll not need identityfactoryoptions. can inject iuserstore, dbcontext, idataprotectionprovider, , else need through kind of di prefer.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -