Prism 和在 Prism 中使用 Unity IoC
我是 Prism 的新手。我从 SO 上的问题和各种博客中了解了很多。我正在使用最新版本 - V2,
我想要一些对你们来说可能很简单的事情的解释,但它只是没有进入我的大脑(对此很小)。 我没有第一次就把事情做好,为此我花了两个多星期的时间查看各种博客、网络广播......,我想开始一个项目并学习。这数百个网站上的信息量巨大且难以消化。 目前我的项目是这样设置的 Shell -- → 菜单模块- ViewModel -- -->菜单服务-->菜单存储库 --- 数据
全部位于不同的程序集
MyShell --- MenuModule ---MyServices --- Myrepository
Shell 需要稍后引用模块(我确信我可以使用字符串添加它)。
ViewModel 具有对 View 的引用 - 目前可以使用它
View Model 需要使用菜单服务,而菜单服务使用存储库
所有这些都是通过构造函数注入构建的。我现在通过模块引用 MyService 和 Myrepository 项目,然后在模块级别注册类型来使其工作。 但这感觉不太好。我不想硬引用任何项目。如果我们引用项目为什么要使用 IoC。在 MenuModule.cs (位于模块的根目录中)中,我可以使用 Unity 容器注册视图 我想我感觉这个问题的答案可能在于第一个问题
- 配置文件是答案/ 我应该使用配置文件吗 真正的脱钩?
- 如果(以某种方式)我们可以 从代码中注册类型,我们应该 模块级别的寄存器类型( I 不想对项目进行硬引用)
- 我需要知道 提前接口,你也一样 建议单独组装 接口?
如果这些问题听起来很愚蠢,请耐心等待
I am a total newbie on Prism. I have been getting to understand a lot from questions on SO and from various Blogs. I am using latest build – V2
I want some explanations on things that may be pretty easy things for you guys but it’s just not getting into my brains (small one for that).
Instead of doing it all right the first time , for which I have spent more than two weeks looking at various blogs, webcast …., I thought to start a project and learn. The amount of information on those hundreds of sites was overwhelming and difficult to digest.
Currently my project is setup like this
Shell -- Menu Module- ViewModel - - -> Menu Service -- -- > Menu Repository --- Data
All are in different assembly
MyShell --- MenuModule ---MyServices -- Myrepository
Shell is required to reference modules ( thought I am sure I can add it using string) later on .
ViewModel has a reference to View - Can live with it for now
View Model requires to use menu service and menu service uses repository
All are built with constructor injection. I have it working now by having module reference MyService and Myrepository projects and then registering types at module level.
But this does not feel good. I don’t want to hard reference any projects. If we are referencing projects why use IoC. In MenuModule.cs ( which is in the root of module) I can register views with unity container
I think I am getting a feel that the answer to this one may lie in the first question
- Is Configuration file the answer/
Should I use configuration file for
true decoupling? - If (somehow) we can
register types from code, should we
register types at module level ( I
don’t want to have hard reference to projects) - I need to know the
Interfaces in advance so do you
recommend separate assembly for just
Interfaces?
Bear with me if the questions sound real stupid
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要配置文件来实现真正的解耦。您所需要的只是在 shell 的引导程序中注册您的类型。我通常会像这样分解我的项目和参考。
合同组装
(仅包含一些简单的类型和接口)
引用者:
Shell
(包含Contract组件中定义的接口的具体实现)
引用者:
模块
(声明对 Contracts 程序集中定义的接口的依赖关系,例如 IMenuRegistry)
引用者:
这是我放在一起的一个示例项目。在此示例中,为了简单起见,我从 shell 引用了该模块,但您可以删除该引用并使用目录模块目录在运行时加载已编译的模块:
http://dl.getdropbox.com/u/376992/CAGMenus.zip
希望这有帮助,
安德森
You don't need a configuration file for true decoupling. All you need is to register your types in your shell's bootstrapper. I usually break up my projects and refs like this.
Contract Assembly
(Contains only a few simple types and interfaces)
Referenced by:
Shell
(Contains concrete implementations of interfaces defined in Contract assembly)
Referenced by:
Modules
(Declares dependencies on interfaces defined in Contracts assembly, for instance IMenuRegistry)
Referenced by:
Here's a sample project I put together. In this sample I reference the module from the shell for simplicity's sake, but you can remove that reference and use a directory module catalog to load the compiled module at runtime:
http://dl.getdropbox.com/u/376992/CAGMenus.zip
Hope this helps,
Anderson
您绝对走在正确的道路上。使用配置文件注册您的类型,并将接口放在单独的程序集中。
You're definitely on the right track. Use the configuration file to register your types, and put the interfaces in a separate assembly.