CAB:获取服务实例而不引用 WorkItem
是否可以在没有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于所有服务都在 WorkItem 或 rootWorkItem 上下文中注册,根据 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.