注册ISecureDataFormat< AuthenticationTicket>与团结

本文关键字:AuthenticationTicket ISecureDataFormat 注册 | 更新日期: 2023-09-27 18:02:06

我正在尝试注册ISecureDataFormat与Microsoft Unity。我试着像这样注册它:

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

然而,当我试图到达类时,我遇到了以下错误:

当前类型,Microsoft.Owin.Security.ISecureDataFormat ' 1[Microsoft.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或其他东西,但目前我卡住了。

注册ISecureDataFormat< AuthenticationTicket>与团结

终于成功了:

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")));
相关文章:
  • 没有找到相关文章