Prism 和在 Prism 中使用 Unity IoC

发布于 2024-08-03 19:53:53 字数 830 浏览 1 评论 0原文

我是 Prism 的新手。我从 SO 上的问题和各种博客中了解了很多。我正在使用最新版本 - V2,

我想要一些对你们来说可能很简单的事情的解释,但它只是没有进入我的大脑(对此很小)。 我没有第一次就把事情做好,为此我花了两个多星期的时间查看各种博客、网络广播......,我想开始一个项目并学习。这数百个网站上的信息量巨大且难以消化。 目前我的项目是这样设置的 Shell -- → 菜单模块- ViewModel -- -->菜单服务-->菜单存储库 --- 数据

全部位于不同的程序集

MyShell --- MenuModule ---MyServices --- Myrepository

Shell 需要稍后引用模块(我确信我可以使用字符串添加它)。

ViewModel 具有对 View 的引用 - 目前可以使用它

View Model 需要使用菜单服务,而菜单服务使用存储库

所有这些都是通过构造函数注入构建的。我现在通过模块引用 MyService 和 Myrepository 项目,然后在模块级别注册类型来使其工作。 但这感觉不太好。我不想硬引用任何项目。如果我们引用项目为什么要使用 IoC。在 MenuModule.cs (位于模块的根目录中)中,我可以使用 Unity 容器注册视图 我想我感觉这个问题的答案可能在于第一个问题

  1. 配置文件是答案/ 我应该使用配置文件吗 真正的脱钩?
  2. 如果(以某种方式)我们可以 从代码中注册类型,我们应该 模块级别的寄存器类型( I 不想对项目进行硬引用)
  3. 我需要知道 提前接口,你也一样 建议单独组装 接口?

如果这些问题听起来很愚蠢,请耐心等待 

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

  1. Is Configuration file the answer/
    Should I use configuration file for
    true decoupling?
  2. 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)
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一指流沙 2024-08-10 19:53:53

您不需要配置文件来实现真正的解耦。您所需要的只是在 shell 的引导程序中注册您的类型。我通常会像这样分解我的项目和参考。

合同组装
(仅包含一些简单的类型和接口)

引用者:

  • Shell
  • Modules

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
  • Modules

Shell
(Contains concrete implementations of interfaces defined in Contract assembly)

Referenced by:

  • No one

Modules
(Declares dependencies on interfaces defined in Contracts assembly, for instance IMenuRegistry)

Referenced by:

  • No one (I use a Directory Module to search for modules in a directory)

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

风和你 2024-08-10 19:53:53

您绝对走在正确的道路上。使用配置文件注册您的类型,并将接口放在单独的程序集中。

You're definitely on the right track. Use the configuration file to register your types, and put the interfaces in a separate assembly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文