当使用windsor容器创建以下MVP设计(用于winforms)时,我面临循环依赖的问题.
我的演示者取决于视图和模型:
ConcretePresenter(IView view, IModel model)
{
this.view = view;
this.model = model;
}
Run Code Online (Sandbox Code Playgroud)
我的观点取决于主持人:
ConcreteView(ConcretePresenter presenter)
{
//actual requirement that the presenter use the current instance of the view and a model object
//new presenter(this, new model())
this.presenter = presenter;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Windsor城堡(在单独的合成根类中)注册所有组件,如下所示:
IWindsorContainer container;
container = new WindsorContainer();
container.Register(Component.For<ConcretePresenter>().ImplementedBy<ConcretePresenter>());
container.Register(Component.For<IModel>().ImplementedBy<ConcreteModel>());
container.Register(Component.For<IView>().ImplementedBy<ConcreteView>());
Run Code Online (Sandbox Code Playgroud)
解决View会出现循环引用问题:
container.Resolve<ConcreteView>(); //doesn't resolve because of cyclic dependency
Run Code Online (Sandbox Code Playgroud)
一种可能的解决方案是从视图中删除构造函数注入并单独解析presenter. 但这导致我在两个地方使用容器,我不打算这样做,可能是错的.
ConcreteView()
{
container.Resolve<ConcretePresenter>(); //resolving at 2 different points
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的解决方案.我在MVP本身做错了吗?
背景
我正在尝试使用AOP为新项目实现日志记录和异常处理.我希望通过Windows窗体应用程序的所有3层应用它.我使用温莎城堡作为容器.
我已成功通过AOP应用日志记录到一个非常简单的示例.但是将其扩展到winforms应用程序是很困难的.
问题
我设法在容器中注册主窗体并应用日志记录方面.但是这个方面正在被winforms所有事件击中.(例如:get_ForeColor,get_BackColor,OnControlAdded,DefWndProc,DestroyHandle..etc)
我实际需要记录的事件和方法没有显示在日志文件(方面)中.我在这做错了什么 AOP是否始终需要接口实现?
我还想知道AOP的框架(或架构)应该是什么样子.如何以及在何处进行3层所有组件的注册.它应该在应用程序启动时吗?任何示例的链接都将非常有用.
PS:这是我第一次尝试实施AOP.要添加到它我必须在vb.net中编码我不太满意.我也不能使用Post Sharp(资金是一个问题).