如何使用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