CAB:获取服务实例而不引用 WorkItem

发布于 2024-11-14 12:39:06 字数 87 浏览 7 评论 0原文

是否可以在没有 WorkItem 上下文的情况下获取服务实例? 我有一些类需要访问某些服务,我想知道是否可以在不显式地将这些服务注入类中的情况下获取这些服务。

Is it possible to get an instance of a service without having a WorkItem context?
I have a some classes that need to access some services, and i'm wondering if it's possible to get those services without explicitly injecting those services in the class.

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

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

发布评论

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

评论(1

執念 2024-11-21 12:39:06

由于所有服务都在 WorkItemrootWorkItem 上下文中注册,根据 CAB/SCSF 的设计规则,这是不可能的。

请详细说明为什么您无法在 WorkItem 中注册该服务并从那里获取它。 CAB/SCSF 提出了管理企业应用程序的最佳实践,这取决于我们从中受益多少。

但如果确实有必要,您可以拥有一个静态类(它可以充当以单例方式实现的服务)并在您的业务功能模块中引用此程序集来获取它。

这是一个糟糕的黑客行为,但在技术上是可行的。

As all the services are registered in WorkItem or rootWorkItem context its not possible according to the design rules of CAB/SCSF.

Please elaborate why you cannot register the service in WorkItem and get it from there. CAB/SCSF has proposed the best practices to manage an enterprise application, its upto us how much we benefit from it.

But if its really necessary you can have a static class (which can act as service implemented in singleton way) in Infrastructure.Library and refer this assembly in your Business or Functional module to get it.

Its a bad hack but technically doable.

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