我添加了UserStore的自定義實現。對於用戶存儲構造我注入UserRepository我怎麼能註冊一個簡單的注射器容器注入標識UserStore的自定義實現
我的代碼就像
public class UserStore : IUserStore<User>, IUserLoginStore<User>, IUserPasswordStore<User>,
IUserSecurityStampStore<User>, IUserEmailStore<User>
{
private readonly IRepository<User> _userRepository;
public UserStore(IRepository<User> userRepository)
{
_userRepository = userRepository;
}
//other implementations
}
我的UserManager類
public class UserStoreManager<T> : UserManager<User> where T : class
{
public UserStoreManager(IUserStore<User> store) : base(store)
{
}
}
更新
我有通過這樣的註冊試用了這個
container.Register<IUserStore<User>, UserStore>(Lifestyle.Scoped);
container.Register<UserManager<User>, UserStoreManager<User>>(Lifestyle.Scoped);
然後我得到一個異常
我不知道如何註冊IUserStore到容器我試着用這個'container.Register>(()=> new UserStore(),Lifestyle.Scoped);'但需要使用IRepository初始化的默認構造函數 type –
Gayan
你不能註冊類型與簡單的注入器,而不是添加一個初始化器(如果你必須添加lambda進行初始化,你不能做container.Resolve>()來使用它作爲參數嗎? –
Icepickle
@Ippickle我不確定我是否正確理解了你,請你添加一些代碼示例? – Gayan