简体   繁体   English

视图,演示者和界面之间的依赖关系

[英]dependencies between view, presenter and interface

I'm in front of a classic circular dependencies problem but the solution I've found (create a third assembly) does not seem to be ok with my view-presenter pattern. 我遇到了经典的循环依赖问题,但是我发现的解决方案(创建第三个程序集)似乎不适用于我的视图呈现器模式。

I need to reference my presenter in my view assembly I need to reference my interface(which are in the same assembly than the presenter) in my view assembly 我需要在我的视图程序集中引用我的演示者我需要在我的视图程序集中引用我的界面(与演示者在同一程序集中)

ok so I reference my presenter / interface assembly in the view since they are all in the same place. 好的,因为它们都在同一位置,所以我在视图中引用了presenter / interface组件。

and now the problem comes : I need to reference my view in my presenter/interfaces assembly to be able to use one of my view type (non-system type, custom control) to define a property and accessors in my interface. 现在问题来了:我需要在presenter / interfaces程序集中引用我的视图,以便能够使用我的视图类型之一(非系统类型,自定义控件)在我的界面中定义属性和访问器。 I can't because of a circular dependency, and I think that even if I move my interface in a third assembly, I will always have a CD between this new assembly and the view (because my view needs my interface and my interface needs my view) 我不能因为循环依赖,而且我认为即使我在第三个程序集中移动界面,在这个新程序集和视图之间也总会有一张CD(因为我的视图需要我的界面,而接口需要我的界面视图)

the goal is to set a property and accessors in my interface to be able to access to a control in my view from my presenter so I need a reference to use my control type in the interface. 目标是在我的界面中设置一个属性和访问器,以便能够从我的演示者访问我视图中的控件,因此我需要引用才能在界面中使用控件类型。

It's not easy to be clear so feel free to ask me more, 要弄清楚并不容易,所以随时问我更多,

Thanks a lot in advance to everybody. 在此先感谢大家。

Best regards. 最好的祝福。

Interfaces should live on there own as a rule. 通常,接口应该独立存在。 When you need isolation of implementations (such as in the reference between views and presenters) you use an interface. 当需要隔离实现时(例如,在视图和演示者之间的引用中),请使用一个接口。 So you should have a presenter interface and view interface, if it is necesarry for them both to know of eachother rather than just one knowing of the other. 因此,如果有必要让他们俩彼此了解,而不仅仅是彼此之间的了解,那么您应该具有演示者界面和查看界面。

Example: 例:

Interface.dll: Interface.dll:

public interface IMyView { string title; }
public interface IMyPresenter { string GetTitle(); }

View.dll: View.dll:

public MyView : IMyView
{
    private IMyPresenter _myPresenter;
    public string Title { get { return _myPresenter.GetTitle(); } }
}

Presenter.dll: Presenter.dll:

public MyPresenter : IMyPresenter
{
    private IMyView _myView;

    public string GetTitle()
    {
        return ResourceManager["titleResource"];
    }
}

Though in my understanding of a model view presenter, doesn't the view just publicize everything the presenter needs, and the view doesn't know about the presenter, rather you hand the IView to the presenter and it binds itself to the view everywhere necesarry? 尽管以我对模型视图演示者的理解,该视图不仅公开了演示者需要的所有内容,而且该视图也不了解演示者,而是将IView交给演示者,并将其自身绑定到所有需要的视图上?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM