我正在關注Onion體系結構並使用Identity Framework。在我的核心項目,我有:簡單注射器身份UserManager <AppUser,Int32>註冊錯誤
public interface IUserRepository : IDisposable
{
// Repository methods.......
}
在我Architecture.Repository,我有
public class UserRepository : IUserRepository
{
// This is Identity UserManager
private readonly UserManager<AppUser, int> _userManager;
private readonly IAuthenticationManager _authenticationManager;
private bool _disposed;
public UserRepository(UserManager<User, int> userManager,
IAuthenticationManager authenticationManager)
{
_userManager = userManager;
_authenticationManager = authenticationManager;
}
}
在我的解決依賴的項目,我有:
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(IocConfig),
"RegisterDependencies")]
namespace AdShad.Infrastructure.DependencyResolution
{
public class IocConfig
{
public static void RegisterDependencies()
{
var container = new Container();
container.RegisterWebApiRequest<IUnitOfWork, UnitOfWork>();
container.RegisterWebApiRequest<IUserRepository, UserRepository>();
container.RegisterManyForOpenGeneric(typeof(IRepository<>),
typeof(BaseRepository<>).Assembly);
container.RegisterWebApiRequest<IEntitiesContext, MyContext>();
container.RegisterWebApiRequest(
() => HttpContext.Current.GetOwinContext().Authentication);
container.Verify();
HttpConfiguration config = new HttpConfiguration
{
DependencyResolver =
new SimpleInjectorWebApiDependencyResolver(container)
};
}
}
}
在container.Verify()
,我我得到以下錯誤:
An exception of type 'System.InvalidOperationException' occurred in SimpleInjector.dll but was not handled in user code
Additional information: The configuration is invalid. Creating the instance for type IUserRepository failed. The registered delegate for type IUserRepository threw an exception. No registration for type UserManager could be found and an implicit registration could not be made. The constructor of type UserManager contains the parameter of type IUserStore with name 'store' that is not registered. Please ensure IUserStore is registered, or change the constructor of UserManager.
有人可以指導我做錯了什麼,我需要做些什麼來糾正它?
但是你沒有在容器中註冊'UserManager' ......並且異常在說這個,UserManager'構造函數需要'IUserStore'參數,所以SimpleInjector不能創建它。你需要在'UserManager'類的容器或委託中註冊'IUserStore'類 –
但是我沒有任何IUserStore,也沒有那個接口的具體類,我怎麼註冊? –
@UsageKhalid你需要選擇一個'UserStore'實現或者創建你自己的([here](http://www.asp.net/identity/overview/getting-started/adding-aspnet-identity-to-an -empty-or-existing-web-forms-project),[這裏](http://www.asp.net/identity/overview/extensibility/overview-of-custom-storage-providers-for-aspnet-identity)等等) – qujck