本文介绍了简单的喷油器和默认AccountContoller依赖问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的注射问题我的网络API项目。我的用户默认的AccountController 由VS生成的。

I have problem with Simple Injector in my Web Api project. I user default AccountController generated by VS.

public AccountController(ApplicationUserManager userManager,
    ISecureDataFormat<AuthenticationTicket> accessTokenFormat)

在我的配置文件我注册:

In my configuration file I register:

var container = new Container();

// This is an extension method from the integration package.
container.RegisterWebApiFilterProvider(config);
container.RegisterWebApiControllers(config);

container.Register<IInitializeService, InitializeService>();
container.Register<IFolderRepository, FolderRepository>();
container.Register<IUserRepository, UserRepository>();
container.Register<ILogger, Logger>();

//Authentication Wrap
container.Register<IUserStore<User, Guid>, ApplicationUserStore>();
container.Register<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
container.Register<ISecureDataFormat<AuthenticationTicket>,
    SecureDataFormat<AuthenticationTicket>>();
container.Register<IDataProtector>(
    () => new DpapiDataProtectionProvider().Create("ASP.NET Identity"));

container.Verify();

// 4. Register the container as MVC3 IDependencyResolver.
DependencyResolver.SetResolver(new SimpleInjectorWebApiDependencyResolver(container));
config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);

我虽然是简单的喷油器将是足够的智慧来处理所有建设负责默认标识的依赖性,而我不会需要手动注册它们,但我发现了异常,如果我不会注册。

I though that Simple Injector will be smart enough to handle all build in dependences responsible for default identity and i wont need to register them manually, but I'm getting exceptions if I wont register them.

仍然得到异常:

型SecureDataFormat的构造函数中包含的类型ITextEn $ C $铬名为'EN codeR'未注册的参数。请确保ITextEn codeR在容器中注册或更改SecureDataFormat的构造函数。

有没有什么办法来自动处理?

Is there any way to handle that automatically?

推荐答案

我实现了一个网页API,我写了这个code。
这对我的作品

I implemented a Web Api and I wrote this code.This works for me

container.RegisterWebApiRequest<ISecureDataFormat<AuthenticationTicket>, SecureDataFormat<AuthenticationTicket>>();
container.RegisterWebApiRequest<ITextEncoder, Base64UrlTextEncoder>();
container.RegisterWebApiRequest<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
container.RegisterWebApiRequest<IDataProtector>(() => new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider().Create("ASP.NET Identity"));

这篇关于简单的喷油器和默认AccountContoller依赖问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:50