我以前在 ASP.Net MVC 中编码,现在我有一个 WinForms 项目。我读到 MVP 模式最适合 WinForms。但是,我对如何将多个依赖项注入 Presenter 感到困惑。
例如,我需要加载一个名为“UserLoginView”的视图。演示者需要 3 个参数。
public partial class UserLoginView : IUserLoginView
{
public event Action OnFormLoad;
private UserLoginPresenter _userLoginPresenter;
public UserLoginView()
{
InitializeComponent();
//This is my problem
var userService = EngineContext.Current.Resolve<IUserService>();
var authenticationService = EngineContext.Current.Resolve<IAuthenticationService>();
_userLoginPresenter = new UserLoginPresenter(this, userService,
authenticationService);
}
}
public class UserLoginPresenter
{
private readonly IUserLoginView view;
private readonly IUserService _userService;
private readonly IAuthenticationService _authenticationService;
public UserLoginPresenter(IUserLoginView userLoginView,
IUserService userService,
IAuthenticationService authenticationService)
{
this.view = userLoginView;
this._userService = userService;
this._authenticationService = authenticationService;
}
...
将依赖项注入演示者的正确方法是什么?
请我需要一个手,伙计们。谢谢你。