Print Page | Close Window

[Resolved]Services ????

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=471
Printed Date: 19-Oct-2025 at 10:18pm


Topic: [Resolved]Services ????
Posted By: orcities
Subject: [Resolved]Services ????
Date Posted: 04-Oct-2007 at 2:36pm
I am trying to create a Service for some global variables that I need. The problem is that every time I try to get the data it is null.
 
Am I doing this right.
 
1. Create a class in the Foundation.Services directory. MyService
2. Added a property with get and set properties.
3. Injected the variable into the class that I want to use them

private GlobalService mGlobalService;

 

[InjectionMethod]

public void InjectController(GlobalService pGlobals)

{

mGlobalService = pGlobals;

}

Value is always null.




Replies:
Posted By: Bill Jensen
Date Posted: 04-Oct-2007 at 3:54pm
The service needs to be added to the root workitem's Services collection in FoundationModule.cs.
 
B.


Posted By: orcities
Date Posted: 04-Oct-2007 at 5:08pm
I found that after a few hours of looking for the issue. Tx for getting back to me.


Posted By: orcities
Date Posted: 05-Oct-2007 at 7:17am
I added my service to the AddFoundationServices of the FoundationModule as follows:

pServices.AddNew<GlobalService, LOC.CEMS.Interface.Services.IAppGlobalsService>();

On the module/view where I am setting the value I do the following (in a page controller):

private GlobalService mGlobalService;

 

[InjectionMethod]

public void InjectController(GlobalService pGlobals)

{

    mGlobalService = pGlobals;

}

 
In a different module I am trying to get the current value as follows (in a view presenter):

private GlobalService mGlobalService;

 

[InjectionMethod]

public void InjectController(GlobalService pGlobals)

{

   mGlobalService = pGlobals;

}

It says the value was never set. Why does it not seem to be static?



Posted By: orcities
Date Posted: 05-Oct-2007 at 7:24am

My collection object wasn't static. Once I changed that it worked fine.



Posted By: Bill Jensen
Date Posted: 05-Oct-2007 at 10:43am
Glad this worked out OK.
 
When you inject the service, you should use the service's interface rather than it's implementation class.  That way you can change the implementation or have different implementations in different workitems without changing the injection code.
 
B.



Print Page | Close Window