问题描述
我在Web API 2项目中使用ASP.NET Identity 2.2,但不确定如何使用 Autofac 连接AccountController
的ISecureDataFormat<AuthenticationTicket>
依赖项.
I am using ASP.NET Identity 2.2 in a Web API 2 project but I am unsure how to wire up the ISecureDataFormat<AuthenticationTicket>
dependency of the AccountController
using Autofac.
我尝试过:
builder.RegisterType<ISecureDataFormat<AuthenticationTicket>>()
.As<TicketDataFormat>();
并出现错误:
我遇到的所有问题似乎都没有使用ASP.NET Identity的最新稳定版本来解决.
None of the questions I came across seem to work using the latest stable release of ASP.NET Identity.
非常感谢您的帮助.
推荐答案
您必须做相反的事情.使用 Autofac ,您可以将一种类型注册为服务.
You have to do the oposite. With Autofac you register a type as a Service.
builder.RegisterType<TicketDataFormat>()
.As<ISecureDataFormat<AuthenticationTicket>>();
并基于此答案,看来您还需要注册IDataSerializer<AuthenticationTicket>
和IDataProtector
实现.
and based on this answer, it seems that you also need to register a IDataSerializer<AuthenticationTicket>
and a IDataProtector
implementation.
builder.RegisterType<TicketSerializer>()
.As<IDataSerializer<AuthenticationTicket>>();
builder.Register(c => new DpapiDataProtectionProvider().Create("ASP.NET Identity"))
.As<IDataProtector>();
这篇关于使用Autofac在Web API 2 AccountController中注入ISecureDataFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!