我已经开始在我的几个表单的 Windows 表单应用程序中使用 MVP 模式。这些表单创建一个演示者并将它们自己传回给演示者。
我没有使用任何特定的框架,表单仍然可以打开其他表单。
我是否应该更改此设置以便演示者可以打开其他表单(通过视图)?我相信必须使用 IOC 框架来做到这一点?
这可能会节省我在 UI 中打开相关表单的逻辑,并允许我从表单中删除对演示者的引用。
我已经开始在我的几个表单的 Windows 表单应用程序中使用 MVP 模式。这些表单创建一个演示者并将它们自己传回给演示者。
我没有使用任何特定的框架,表单仍然可以打开其他表单。
我是否应该更改此设置以便演示者可以打开其他表单(通过视图)?我相信必须使用 IOC 框架来做到这一点?
这可能会节省我在 UI 中打开相关表单的逻辑,并允许我从表单中删除对演示者的引用。
You should have a separate class that is responsible for creating / managing forms. I would recommend using the Command pattern to invoke the code that opens a new form. It will end up scaling a lot better and you can change the Command implementation to do different things. In my projects, I just do the data changes in the form itself, but anything that interacts with the "application" is delegated to a Command object.
You don't NEED an IOC framework to do this, but it helps. If you just have simple needs, you can keep it simple.
I have a WinForms MVP example on my site here: ModelViewPresenter. I don't use any IOC containers, but structure the code such that using one would be a quick hop.
我正在对几个 winforms 项目做类似的事情,一个用于工作,一个用于家庭。
我的解决方案是为视图使用工厂,允许调用者访问并将消息传递给新的演示者。在某些情况下,我通过将服务接口放置在演示者本身或可以注入的中间类上来进一步抽象它们。