我有一个ASP.NET页面实现我的视图,并在页面构造函数中创建演示者。 Phil Haack's post providing was used as the starting point,我只是通过帖子中的例子来说明问题。ASP.NET MVP注入服务依赖关系
public partial class _Default : System.Web.UI.Page, IPostEditView {
PostEditController controller;
public _Default()
{
this.controller = new PostEditController(this, new BlogDataService());
}
}
什么是注入BlogDataService实例的最佳方法?我发现这些例子在Page类中使用属性标记了依赖注入框架解析的属性。
但是,我更喜欢使用构造函数方法进行测试。
有没有人有输入或可能链接到上述的良好实施。我宁愿Ninject,但StructureMap或Windsor只要流利就可以。
感谢您的任何反馈意见。
我喜欢它,谢谢。 – blu
使用这种方法,该视图现在知道IBlogDataService,它只应由演示者知道。有没有办法使用传递当前视图对象和配置的IBlogDataService实例的DI容器来构造演示者? – Scott
使用服务定位器被认为是IoC的反模式。一定有更好的方法。 –