structuremap Web Api 2 Account Controller and individual accounts

无人久伴 提交于 2020-01-13 08:59:49

问题


I pretty New at IOC and web-api 2, but have got StructureMap to work on my own Controllers in web-api 2. What I don't have managed is to use StructureMap on the AccountController using Individual Accounts. I use AccountController out of the Box, and what I have managed so far is following:

  1. In Ioc.cs I have added following (Because of errors)

      x.For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>();
      x.For<DbContext>().Use(() => new ApplicationDbContext());
      x.For<ISecureDataFormat<AuthenticationTicket>()
           .Use<SecureDataFormat<AuthenticationTicket>>();
    

But now I'm stuck With this error:

"No default Instance is registered and cannot be automatically determined for type IDataSerializer<AuthenticationTicket>"

I realy dont know what to do here. I have tried to find a detault instance of IDataSerializer, but no Luck.

By the way... I have installed the Nuget package "Structuremap.webapi2"


回答1:


Solved it!

Add this configuration to the IoC.cs or DefaultRegistry:

        For<ISecureDataFormat<AuthenticationTicket>>().Use<SecureDataFormat<AuthenticationTicket>>();
        For<IDataSerializer<AuthenticationTicket>>().Use<TicketSerializer>();
        For<IDataProtector>().Use(() => new DpapiDataProtectionProvider().Create("ASP.NET Identity"));
        For<ITextEncoder>().Use<Base64UrlTextEncoder>();

        For<Microsoft.AspNet.Identity.IUserStore<ApplicationUser>>().Use<Microsoft.AspNet.Identity.EntityFramework.UserStore<ApplicationUser>>();
        For<System.Data.Entity.DbContext>().Use(() => new ApplicationDbContext());


来源:https://stackoverflow.com/questions/23962597/structuremap-web-api-2-account-controller-and-individual-accounts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!