2016-08-12 26 views
0

我正在嘗試向Microsoft Unity註冊ISecureDataFormat。我試圖像這樣註冊它:使用Unity註冊ISecureDataFormat <AuthenticationTicket>

container.RegisterType<ISecureDataFormat<AuthenticationTicket>>(); 

但是我遇到下面的錯誤,當我試圖達到類:

當前類型,Microsoft.Owin.Security.ISecureDataFormat`1 [微軟.Owin.Security.AuthenticationTicket], 是一個接口,無法構建。是否缺少 類型映射從微軟沒有DI

原始代碼的工作是這樣的:

public AccountController(ApplicationUserManager userManager, 
    ISecureDataFormat<AuthenticationTicket> accessTokenFormat) 
{ 
    UserManager = userManager; 
    AccessTokenFormat = accessTokenFormat; 
} 

public ApplicationUserManager UserManager 
{ 
    get 
    { 
     return _userManager ?? Request.GetOwinContext().GetUserManager<ApplicationUserManager>(); 
    } 
    private set 
    { 
     _userManager = value; 
    } 
} 

public ISecureDataFormat<AuthenticationTicket> AccessTokenFormat { get; private set; } 

也許我需要使用InjectionFactory或東西,但此刻我被困。

回答

0

終於得到它的工作:

container.RegisterType(typeof(ISecureDataFormat<>), typeof(SecureDataFormat<>)); 
container.RegisterType<ISecureDataFormat<AuthenticationTicket>, SecureDataFormat<AuthenticationTicket>>(); 
container.RegisterType<ISecureDataFormat<AuthenticationTicket>, TicketDataFormat>(); 
container.RegisterType<IDataSerializer<AuthenticationTicket>, TicketSerializer>(); 
container.RegisterType<IDataProtector>(
    new InjectionFactory(c => new DpapiDataProtectionProvider().Create("ASP.NET Identity"))); 
+0

我想給予好評這個答案,但你可以建議的文檔,該代碼。 –

+0

https://msdn.microsoft.com/en-us/library/microsoft.owin.security(v=vs.113).aspx – Ogglas