ASP.NET Identity 2 - 注入ISecureDataFormat <>

par*_*ent 2 unity-interception asp.net-identity asp.net-identity-2

我在这里描述的问题没有答案,仅使用Unity.

我正在尝试注册ISecureDataFormat<>最新的VS2013(更新2)SPA/Web Api模板.

我试过了

container.RegisterType(typeof(ISecureDataFormat<>), typeof(SecureDataFormat<>));
container.RegisterType<ISecureDataFormat<AuthenticationTicket>, SecureDataFormat<AuthenticationTicket>>();
container.RegisterType<ISecureDataFormat<AuthenticationTicket>, TicketDataFormat>();
Run Code Online (Sandbox Code Playgroud)

它"有效"但不是真的,因为它抱怨了该树中的下一个依赖性,IDataSerializer ......然后是下一个IDataProtector,我发现没有实现.

Jos*_*h C 10

我使用以下映射解决了SimpleInjector中的以下错误

container.Register<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
container.Register<IDataProtector>(() => new DpapiDataProtectionProvider().Create("ASP.NET Identity"));
Run Code Online (Sandbox Code Playgroud)

为了弄清楚使用了什么序列化程序,我注意到AccountsController中的ISecureDataFormat泛型参数是AuthenticationTicket类型.在检查IDataSerializer命名空间时,TicketSerializer实现了IDataSerializer.

为了找出IDataProtector,我再次查看了IDataProtector命名空间,并找到了IDataProtectionProvider的实现.