2015-10-02 14 views
9

あなたはアイデンティティ2.0で働いてきた場合は、コードのこの作品を見てきました:IdentityFactoryOptions <AppIdentityUserManager>オプションはどのように設定されますか?

 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; 
     } 

私はそれを理解しています。私のアプリケーションのoptions.DataProtectionProvider(明らかにパラメータとして渡される)はnullです。どのように設定されていますか(場合によってはそうではありません)。私が見てきたすべての場所に、正確なコードスニペットがありますが、DataProtectionProviderの設定についての説明はありません。

編集:私はDataProtectionProvider in the Identity sample projectを読んでいますが、これはUserTokenProviderが何であるかを説明していますが、IdentityFactoryOptionsオブジェクトでどのように設定されているか説明していません。

+1

[IDサンプルプロジェクトのDataProtectionProvider]の可能な複製](http://stackoverflow.com/questions/25685252/dataprotectionprovider-in-theidentity-sample-project) –

+0

重複していない質問は次の場所で編集されています私がそれを信じる理由。 – Duston

答えて

1

ユーザマネージャが作成されたときに設定されます。

あなたはMicrosoft.AspNet.Identity.Owinで定義された拡張機能である、あなたのOWIN Startupクラス、内部のCreatePerOwinContext方法を使用している場合は、その拡張子は新しいIdentityFactoryOptionオブジェクトを作成し、CreatePerOwinContextのパラメータであるFuncに渡します。

CreatePerOwinContextの詳細はthe source code hereです。

public static IAppBuilder CreatePerOwinContext<T>(this IAppBuilder app, 
    Func<IdentityFactoryOptions<T>, IOwinContext, T> createCallback, 
    Action<IdentityFactoryOptions<T>, T> disposeCallback) where 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; 
} 

アプリで独自のDIメカニズムを持っている場合は、自分ですべてのオブジェクトのCreatePerOwinContextアプローチとワイヤーアップの作成を使用する必要はありません。そうすれば、IdentityFactoryOptionsも必要ないでしょう。 IUserStoreDbContextIDataProtectionProviderなど、好きな種類のDIで必要なものを注入するだけです。

関連する問題