PRISM:PRISM 模块是否旨在每个区域只有一个视图?
我真的很困惑模块内部应该包含什么。
当我为许多视图调用 RegisterViewWithRegion 时,它们在模块初始化期间全部加载在一起...所有这些视图都旨在托管在同一区域内,因为它们是同一模块的不同进程。
假设我有一个名为 Inventory 的模块,它包含一个产品视图、一个订单视图等。所有这些视图都与名为“MainRegion”的区域关联,我想在用户请求时实例化这些视图,而不是在模块初始化时。
在我看来,这个谜团的唯一答案是 Prism 模块内部只有一个进程(我称之为),所以这样我最终会得到如下不同的模块:
Inventory.Products.xap
Inventory.Orders .xap
...等等。
是这样吗? 有没有其他选择可以让我将这些进程保留在一个模块内?在这种情况下,这样方便吗?
提前致谢! 让·保罗
I'm really confused about what is supposed to be inside a Module.
When I call RegisterViewWithRegion for many views they are all loaded together during Module initialization... All those views are intended to be hosted inside the same region because they are diferent processes of the same module.
Let-s say that I have a Module named Inventory and it contains a view for Products, a view for Orders, etc. All of them are associated with a region named "MainRegion" and I would like to instantiate those views when user requests them, not when the module gets initialized.
In my mind, the only answer to this enigma is that Prism modules are intended to have (what I call) ONLY ONE process inside, so this way I'll end up with different modules like this:
Inventory.Products.xap
Inventory.Orders.xap
... and so on.
Is that right?
Is there any alternative that let me keep those processes together inside One module? and in this case, is this convenient?
Thanks in Advance!
Jean Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Prism 对实例化视图和显示视图进行了区分。 Prism 4 有一个新的 API,用于按需显示区域,但旧版本也可以完成按需显示。除非您的视图是资源密集型的,否则我建议在引导时加载它们,然后根据用户的请求显示它们。
以下几篇文章应该会有所帮助:
Prism 4.0 Display-on-Demand
按需显示 - 旧版本的 Prism
Prism makes a distinction between instantiating a view and displaying it. Prism 4 has a new API for displaying regions on demand, but display-on-demand can be done with older versions, as well. Unless your views are resource intensive, I'd suggest loading them at bootstrap-time, then displaying them as requested by the user.
Here are a couple of articles that should help:
Prism 4.0 Display-on-Demand
Display-on-Demand - Older Versions of Prism
只是补充一下@David所说的,Prism可以帮助你在逻辑上分离不同的模块,而将每个视图分离到它自己的模块是(a)巨大的杀伤力,以及(b)糟糕的架构。
好的架构是知道如何划分和构建征服应用程序的任务,这意味着知道何时划分事物,有时甚至更重要的是,何时不划分事物。
Just to add to what @David said, Prism helps u logically separating different modules, and separating each view to its own module is (a) a huge overkill, and (b) a bad architecture.
good architecture is knowing how to divide & conquer the tasks of the application, which means knowing when to divide things, and sometimes even more importantly, when not to divide things.
好吧,我想我终于明白它应该如何工作了。
为了奠定这篇文章的基础,假设应用程序模块(不是棱镜模块)是与业务流程中的特定活动相关的视图(以前称为表单)和过程的集合,例如:销售、库存、银行业务...等。
在每个应用程序模块中,我们会找到诸如 Sales.Invoices、Sales.Orders、Inventory.Products、Inventory.Stocks 等流程。
现在,在 prism 中,正如 @Elad 所说,为每个流程创建一个新项目在应用程序模块内部可能是一个巨大的杀伤力,正如@David所说,Prism在实例化视图和显示视图之间进行了区分。
好吧,为了做正确的事情(听听这些人的意见),我决定这样做:
1)区分 Visual Studio 项目和 Prism 模块:
在您的解决方案中,实际上没有必要将应用程序模块分解为不同的项目,您所需要做的就是通过“应用程序模块”创建一个项目
2)在每个“应用程序模块”项目中创建不同的模块初始化器类,每个进程一个,例如:
对于 MyApplicationModule 内的进程“A”:
对于 MyApplicationModule 内的进程“B”:
3) 一旦我们得到了这个,让我们稍微改变一下在 shell 项目上创建模块目录的方式。就我而言,我使用代码逐一添加 Prism 模块,您可以从文件加载模块定义,但原理是相同的:
结论
这样,您的视图将仅被实例化当用户请求这个特定的“业务流程”时,您不需要将解决方案分成更小的部分,因此需要永远编译,并且您的解决方案仍然是“团队友好的”。
谢谢@David & @埃拉德
Well, I guess I finally understand how it's supposed to work.
In order to set the grounds for this post, let's say that an application Module (not a prism module) is a collection of views (previously named Forms) and procedures related to specific activities on a business process, for example: Sales, Inventory, banking... etc.
Inside each Application module, we will find processes like Sales.Invoices, Sales.Orders, Inventory.Products, Inventory.Stocks, etc.
Now, in prism as @Elad says, create a new project for each process inside inside an Application Module may be a huge overkill, And as @David says, Prism makes a distinction between instantiating a view and displaying it.
Well, to do the right thing (which is listen to these guys), I decided to go like this:
1) Differenciate a Visual Studio project from a Prism Module:
It's not really necessary to break Application Modules into different project in your solution, all you need to do is create one project by "Application Module"
2) Create different Module Initializer Classes inside each "Application Module" project, one for each process e.g.:
For Process "A" Inside MyApplicationModule:
For Process "B" Inside MyApplicationModule:
3) Once we got this, let's change a little bit how your modulecatalog is being created on your shell project. In my case, I'm using code to add Prism Modules one by one, you could load the Modules Definition from a file but the principle is the same:
Conclusion
This way, Your views will be instantiated only when user request this specific "Business Process", you don't need to split your solution into smaller parts so it take forever compiling and your solution still being "team friendly".
Thank you @David & @Elad