如何使用autofac注册ISecureDataFormat<AuthenticationTicket>
?使用Autofac注册ISecureDataFormat <AuthenticationTicket>
我试着注册了这种方式:
builder.RegisterType<SecureDataFormat<AuthenticationTicket>>()
.As<ISecureDataFormat<AuthenticationTicket>>()
.InstancePerLifetimeScope();
,但我得到的错误:
An error occurred when trying to create a controller of type 'AccountController'. Make sure that the controller has a parameterless public constructor. ....
InnerException":{"Message":"An error has occurred.","ExceptionMessage":"None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Microsoft.Owin.Security.DataHandler.SecureDataFormat`1[Microsoft.Owin.Security.AuthenticationTicket]' can be invoked with the available services and parameters
AccountController.cs
public AccountController(ApplicationUserManager _userManager,
IAuthenticationManager authenticationManager,
ISecureDataFormat<AuthenticationTicket> accessTokenFormat)
{
this._userManager = _userManager;
this._authenticationManager = authenticationManager;
this._accessTokenFormat = accessTokenFormat;
}
没有ISecureDataFormat<AuthenticationTicket> accessTokenFormat
在构造函数中一切正常。
SecureDataFormat
#region
Assembly Microsoft.Owin.Security, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
#endregion
using Microsoft.Owin.Security.DataHandler.Encoder;
using Microsoft.Owin.Security.DataHandler.Serializer;
using Microsoft.Owin.Security.DataProtection;
namespace Microsoft.Owin.Security.DataHandler
{
public class SecureDataFormat<TData> : ISecureDataFormat<TData>
{
public SecureDataFormat(IDataSerializer<TData> serializer, IDataProtector protector, ITextEncoder encoder);
public string Protect(TData data);
public TData Unprotect(string protectedText);
}
}
AuhenticationTicket
#region
Assembly Microsoft.Owin.Security, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
#endregion
using System.Security.Claims;
namespace Microsoft.Owin.Security
{
public class AuthenticationTicket
{
public AuthenticationTicket(ClaimsIdentity identity, AuthenticationProperties properties);
public ClaimsIdentity Identity { get; }
public AuthenticationProperties Properties { get; }
}
}
错误消息解释说,* Autofac *无法创建'SecureDataFormat'你能分享它的构造? –
@CyrilDurand我更新了帖子。这堂课来自owin。 – user1031034