2016-08-12 58 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