如何构造ISecureDataFormat< AuthenticationTicket>.团结一致 [英] How to construct ISecureDataFormat<AuthenticationTicket> with unity
问题描述
我的webapi帐户控制器上的构造函数如下:
I have consturctor on my webapi account controller looking like that:
public AccountController(ApplicationUserManager userManager, ISecureDataFormat<AuthenticationTicket> accessTokenFormat)
{
_userManager = userManager;
AccessTokenFormat = accessTokenFormat;
}
但是Unity无法构造ISecureDataFormat<AuthenticationTicket>
,因为构造函数要等到我取下第二个参数后才能工作.
But Unity is not able to consruct the ISecureDataFormat<AuthenticationTicket>
because the constructor is not working untill I taking off the second param.
public AccountController(ApplicationUserManager userManager)
{
_userManager = userManager;
}
如何使用Unity构造第二个参数? 我的Unityconfig:
How I can construct the second param with Unity? My Unityconfig:
.RegisterType<DbContext, ApplicationDbContext>(new HierarchicalLifetimeManager())
.RegisterType<UserManager<ApplicationUser, int>, ApplicationUserManager>()
.RegisterType<ApplicationDbContext>(new HierarchicalLifetimeManager())
.RegisterType<ApplicationUserManager>()
.RegisterType<ISecureDataFormat<AuthenticationTicket>, SecureDataFormat<AuthenticationTicket>>()
.RegisterType<ITextEncoder, Base64UrlTextEncoder>()
.RegisterType<IDataSerializer<AuthenticationTicket>, TicketSerializer>()
//.RegisterType<IDataProtector>(() => new DpapiDataProtectionProvider().Create("ASP.NET Identity"))
.RegisterType<IUserStore<ApplicationUser, int>, CustomUserStore>(new InjectionConstructor(typeof(ApplicationDbContext)))
.RegisterType<IAuthenticationManager>(new InjectionFactory(o => HttpContext.Current.GetOwinContext().Authentication))
.RegisterType<IOwinContext>(new InjectionFactory(o => HttpContext.Current.GetOwinContext()))
.RegisterType<IRepository, Repository>();
推荐答案
您尚未在UnityContainer
中注册类型IDataProvider
(我不知道为什么在统一配置中将其注释掉),但是SecureDataFormat<AuthenticationTicket>
构造函数需要这样做.
You haven't registered type IDataProvider
within UnityContainer
(I don't knows why you comment out that within your unity config) however SecureDataFormat<AuthenticationTicket>
constructor requires that.
public class SecureDataFormat<TData> : ISecureDataFormat<TData>
{
public SecureDataFormat(IDataSerializer<TData> serializer, IDataProtector protector, ITextEncoder encoder)
我也面临着同样的问题.以下统一配置为我解决了问题
I was also facing the same issue. Following unity config resolved issue for me
container.RegisterType<ITextEncoder, Base64UrlTextEncoder>();
container.RegisterType<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
container.RegisterInstance(new DpapiDataProtectionProvider().Create("ASP.NET Identity"));
container.RegisterType<ISecureDataFormat<AuthenticationTicket>, SecureDataFormat<AuthenticationTicket>>();
这篇关于如何构造ISecureDataFormat< AuthenticationTicket>.团结一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!