我已阅读并编码以下示例:http ://timschreiber.com/2015/01/14/persistence-ignorant-asp-net-identity-with-patterns-part-1/ 但该示例使用 Unity 进行 DI,但我我使用 Autofac 作为 ID,当我尝试运行我的项目时,出现以下错误:
在“App.Front.Controllers.HomeController”类型上使用“Autofac.Core.Activators.Reflection.DefaultConstructorFinder”找到的任何构造函数都不能使用可用的服务和参数调用:无法解析参数“Microsoft.AspNet.Identity.UserManager
2[IdentityStore.IdentityUser,System.Guid] userManager' of constructor 'Void .ctor(Microsoft.AspNet.Identity.UserManager
2 ” [IdentityStore.IdentityUser,System.Guid])'。
我的代码:
public class IdentityModule : Module
{
protected override void Load(ContainerBuilder builder)
{
//var dbContextParameter = new ResolvedParameter((pi, ctx) => pi.ParameterType == typeof(DbContext),
// (pi, ctx) => ctx.Resolve<AppContext>());
builder.RegisterType<UserStore>().As<IUserStore<IdentityUser, Guid>>().InstancePerLifetimeScope();
builder.RegisterType<RoleStore>().InstancePerLifetimeScope();
}
}
和
private static void SetAutofacContainer()
{
var builder = new ContainerBuilder();
var mainModules = BuildManager.GetReferencedAssemblies().Cast<Assembly>().Where(p => p.ManifestModule.Name.StartsWith("App.")).ToArray();
builder.RegisterControllers(mainModules);
builder.RegisterAssemblyModules(mainModules);
builder.RegisterFilterProvider();
builder.RegisterSource(new ViewRegistrationSource());
builder.RegisterModule(new EFModule());
builder.RegisterModule(new RepositoryModule());
builder.RegisterModule(new IdentityModule());
builder.RegisterModule(new ServiceModule());
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
请任何人帮助我!