1

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.

Muxa
  • 5,563
  • 6
  • 46
  • 56

1 Answers1

2

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.

Wali
  • 440
  • 1
  • 4
  • 21
  • Thanks for you answer, but what i'm trying to do is instantiate a class that has some dependencies on registered services (so it the framework auto-resolved all the dependencies). And i want to do it from a class that does not have a reference to WorkItem. Hope this makes it clearer. – Muxa Jun 11 '11 at 04:51
  • So from what i have understood, you want to reach to a class and use Services from a class which does not have WorkItem. Am i correct? If yes, then here is what you can do. When you are facing such issues you should carry "WorkItem" along to all the classes by passing WorkItem's reference in constructor while instantiating. Which means, firstly your current class should have WorkItem to be able to pas WorkItem. So first pass WorkItem to this class and then pass it along to the new class. – Wali Jun 13 '11 at 05:38
  • I have myself faced these kind of issues, and I have successfully resolved. Add some more specific details if this does not yield any result. – Wali Jun 13 '11 at 05:38