我非常喜欢IOC和web-api 2,但是我已经在我的web-api 2中使用了StructureMap来处理我自己的控制器.我没有管理的是使用个人帐户在AccountController上使用StructureMap.我使用AccountController开箱即用,到目前为止我所管理的是:
在Ioc.cs中我添加了以下内容(由于错误)
x.For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>();
x.For<DbContext>().Use(() => new ApplicationDbContext());
x.For<ISecureDataFormat<AuthenticationTicket>()
.Use<SecureDataFormat<AuthenticationTicket>>();
Run Code Online (Sandbox Code Playgroud)但是现在我遇到了这个错误:
"没有注册默认实例,无法自动确定类型IDataSerializer <AuthenticationTicket>"
我真的不知道该怎么做.我试图找到IDataSerializer的详细实例,但没有运气.
顺便说一句......我已经安装了Nuget包"Structuremap.webapi2"
我在Web API 2项目中使用ASP.NET Identity 2.2,但我不确定如何连接使用Autofac的ISecureDataFormat<AuthenticationTicket>依赖项.AccountController
我试过这个:
builder.RegisterType<ISecureDataFormat<AuthenticationTicket>>()
.As<TicketDataFo??rmat>();
Run Code Online (Sandbox Code Playgroud)
并得到错误:
类型'Microsoft.Owin.Security.ISecureDataFormat`1 [Microsoft.Owin.Security.Authenticat ionTicket]'不能分配给服务'Microsoft.Owin.Security.DataHandler.TicketDataFormat'
我遇到的所有问题似乎都没有使用最新的ASP.NET身份稳定版本.
任何帮助是极大的赞赏.
asp.net dependency-injection autofac asp.net-web-api2 asp.net-identity-2