本文介绍了身份提供者和Unity依赖注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经下载了此示例中,我可以尝试在ASP.NET MVC 5身份提供者的特点:
http://www.nuget.org/packages/Microsoft.AspNet.Identity.Samples
我已经多次使用统一DI为我的仓库,服务工作和其他东西的单位没有问题。
但现在,当我安装统一DI,我有一个使用身份提供程序,接口和DI很多问题
我刚刚下载的例子的code和我已经配置了统一DI,但我不希望使用统一的标识成员,我想用统一DI只是对我的东西(IRepository, IService,IUnitOfWork等)
我有这样的错误,当我尝试注册一个用户:
I read some post in which they said that I must include something like this, but I don't need to inject dependencies in Identity Provider...
container.RegisterType<UserManager<ApplicationUser>>(new HierarchicalLifetimeManager());
container.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(new HierarchicalLifetimeManager());
Can anyone help me please?
Code Example:
/// <summary>Registers the type mappings with the Unity container.</summary>
/// <param name="container">The unity container to configure.</param>
/// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to
/// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
public static void RegisterTypes(IUnityContainer container)
{
// NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
// container.LoadConfiguration();
// TODO: Register your types here
//container.RegisterType<DbContext, ApplicationDbContext>(new ContainerControlledLifetimeManager());
container.RegisterType<IUnitOfWorkAsync, UnitOfWork>(new PerRequestLifetimeManager());
container.RegisterType<IMainPanelService, MainPanelService>();
container.RegisterType(typeof (IRepositoryAsync<>), typeof (Repository<>));
container.RegisterType<IDataContextAsync, ecoavantisinteractivegciContext>(new PerRequestLifetimeManager());
}
解决方案
Ok, I have resolved my problem, I have injected the dependencies with this method, but I don't understand very well why it's work...
Now, Identity works fine with my Unity DI
container.RegisterType<AccountController>(new InjectionConstructor());
container.RegisterType<RolesAdminController>(new InjectionConstructor());
container.RegisterType<ManageController>(new InjectionConstructor());
container.RegisterType<UsersAdminController>(new InjectionConstructor());
这篇关于身份提供者和Unity依赖注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!