WPF 应用程序 - 模型对象放置/项目结构(在 MVVM 场景中)
我正在使用 Prism v4 和 MEF(MVVM 模式)开发 WPF 单击一次应用程序。我有多个模块驻留在它们自己的程序集中。
我正在尝试找出放置模型对象的位置。
您是否会将它们放置在主要使用它们的程序集中(即使它们可以在其他程序集中使用),或者您是否会创建一个程序集来容纳所有模型(以便更容易在其他程序中使用)?我倾向于后者,但这带来了下面的下一个问题...
您将如何明确分离由不同数据库/服务器填充的模型对象 - 您是否将它们全部聚集在同一个程序集/命名空间中或者将它们分成不同的名称空间/程序集?我正在努力防止由于启动该项目的错误决定而出现问题,并且感谢任何人的反馈。
I'm developing a WPF click once application using Prism v4, and MEF (MVVM pattern). I have multiple modules that reside in their own assemblies.
I'm trying to figure out where to place my model objects.
Would you place them in the assembly where they're primarily used (even though they could be used in other assemblies), or would you create an assembly to house all of the models (to be more easily used in other programs)? I'm leaning towards the latter but that brings be to the next question below...
How would you go about distinctly separating model objects, who are populated from different databases / servers - do you clump them all together in the same assembly / namespace or separate them into different namespaces / assemblies? I'm trying to prevent issues down the road due to a bad decision starting this project and would appreciate anyones feedback.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将模型对象放在它们自己的程序集中。这促进了重用和分离,因为用表示相关的代码“污染”模型要困难得多。
至于你的第二个问题:
如果您计划拥有从多个源填充的模型,我个人会将模型定义放入一个程序集中,然后为每个数据源使用 DAL(在单独的程序集中)。这使得模型定义与数据访问分离,而数据访问仍然是呈现中立的。
如果模型始终从单个数据源填充,那么将其保留在一起(但通过命名空间分隔)可能是一个更简单的选择。
I put the model objects in their own assembly. This promotes reuse as well as separation, as its much more difficult to "pollute" the model with presentation related code.
As for your second question:
If you're planning to have models that are populated from multiple sources, I would personally put the Model definitions in one assembly, then use a DAL (in separate assemblies) per data source. This keeps the model definitions separate from the data access, which in turn is still presentation-neutral.
If the Model will always be populated from a single data source, then keeping this together (but separating via namespaces) is probably a simpler option.