我发现了几个与我发布的问题类似的问题,但是它们没能给我提供我真正需要的答案。我仍在努力使用Microsoft Unity DI实现我的CustomMembershipProvider。
自定义成员资格:
public class CustomMembershipProviderService : MembershipProvider
{
private readonly IUserService _userService;
public CustomMembershipProviderService(IUserService userService)
{
this._userService = userService;
}
public override string ApplicationName
{
...
用户服务:
public class UserService : IUserService
{
private readonly IUserRepository _repository;
private readonly IUnitOfWork _unitOfWork;
public UserService(IUserRepository repository, IUnitOfWork unitOfWork)
{
this._repository = repository;
this._unitOfWork = unitOfWork;
}
...
账户控制器:
public class AccountController : Controller
{
// next line is what I don't feel too sure about what to do?
// shouldn't my controller constructor use an Interface as its property?
private readonly CustomMembershipProviderService _customMembershipProviderService;
public AccountController(CustomMembershipProviderService customMembershipProviderService)
{
this._customMembershipProviderService = customMembershipProviderService;
}
...
我该如何为我的MembershipProvider
类创建一个接口?
我已经尝试过:
public interface ICustomMembershipProvider : MembershipProvider
但我认为这并不起作用,所以我陷入了困境,不知道如何使用我的存储库、UoW、服务和Unity DI来实现MembershipProvider
AccountController
将在构造函数中将ICustomMembershipProvider
作为参数传入? - SOfanaticCustomMembershipProvider
是否可以有一个包含IService
的构造函数?或者我必须在每个方法中使用Global.Container.Resolve<IMyService>()
?除了服务定位器模式之外,是否有其他方法? - SOfanatic