将调用者与订阅者类解耦

发布于 2024-12-11 17:11:04 字数 524 浏览 0 评论 0原文

我正在努力实现一些我不知道是否可能的事情。

背景:我正在创建一个新的 ASP.NET MVC 3 项目,并且希望将 Unity 容器初始化移到 Web 项目之外。

意图:我希望我的 Web 项目与包含 Unity 容器初始化代码的项目分离。

我的解决方案:让单独项目中的 A 类通过委托/事件声明发布事件,并公开引发该事件的方法。

在单独的项目中拥有另一个 B 类,该项目订阅 A 类发布的事件。

让我的 Web 项目中的 Global.asax 初始化 A 类并调用引发事件的方法。

期望:我希望订阅者类(B 类)中的事件处理程序方法在事件引发后立即执行。

Web 项目引用包含 A 类(发布者)的库。包含 B 类(订阅者)的库也引用包含 A 类的库。

有没有办法实现这一点?如果没有,您对我有什么其他建议,以避免在 Web 项目中初始化 Unity 容器?

I am trying to achieve something that I do not know if is possible.

Background: I am creating a new ASP.NET MVC 3 Project and I want to move the Unity container initialization outside of the Web Project.

Intention: I want my Web Project to be decoupled from the project that contains the Unity Container Initialization code.

My Solution: Have Class A in a separate project publish an event through delegate/event declaration and expose a method that raises the event.

Have another Class B in a separate project that subscribes to the event that Class A publishes.

Have Global.asax in my Web Project initialize Class A and call the method that raises the event.

Expectation: I want the event handler method in the subscriber class (Class B) to be executed as soon as the event is raised.

The Web Project references the library that contains Class A (Publisher). The Library that contains Class B (Subscriber) also references the library that contains Class A.

Is there a way to achieve this and if not what other suggestions do you have for me, in order to avoid initializing the Unity Container in the Web Project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

同尘 2024-12-18 17:11:04

因为我无法做到这一点,并且因为我没有收到其他人的消息,所以我正在回答我自己的问题:我想做的事情是不可能的。

Since I have not been able to do this and since I have not heard from anyone else I am answering my own question: What I am trying to do is not possible.

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