CAB and the Offline Application Block

Topics: CAB & Smart Client Software Factory
Jul 7, 2006 at 12:35 PM
originally posted by: JKraft4PIT

Man have i undertaken a task, I have created a smart client using the Offline Application Block using VS2005. I got it working and it is fine.

Now I have found CAb and I find it great, I created a sample application using injection (really great idea), workitems and thier state (another great hing). I have established a good structure for the program and introduced modular loading since this app will have a general client, then administrative tool and reporting so these modules are a great idea.

Now I am combining them and I am having a tough time getting my head around it.

This is what I got.

ShellApplication consists of
ShellWorkitem
- this has the objectblockbuilder instance from the offline block since it will be used across all the modules for offline/online capabilities it was added as a service of type offlineblockbuilder
- the offlineblockbuilder is then started, so message queue is being polled, connection detection is running, events are being forwaded to the shell to say "Online", "Offline" and this is a root state that is forwarded all over hte place, so all smartparts know when we go offline and online. ALL GOOD

JobModule consistes of
JobWorkitem
- has adds the jobServiceAgent which is a OfflineBlock ServiceAgent
- shows the job view in the mainworkspace
JobController
- talks to the jobWorkitem
- needs a reference to the JobServiceAgent
JobView
- talks to Jobcontroller to get work done
JobServiceAgent
- Talks to the Data access layer (Offline Block handles all that)
- Needs to know about the offlineblockbuilder (rootworkitem.service.get(of offlineblockbuilder))

So now I have this all layed out. And all of it seemed to work well until I pressed the button on my JobView to "GetJobs".

This is the events that occured.

btnClick_GetJobs -> JobController.GetJobs() -> JobServiceAgent.GetJobs() BOOOM!!!

So right when I tell the service agent to get the jobs I find my problem. I don't have any idea about the OfflineBlockBuilder.Instance from my RootWorkitem.Services.

I think "no problem" I will just say "RootWorkItem.Services.Get( of Offlineblockbuilder)" and I will have a reference so my service agent can use the offline block to do things. (My controller does know about the JobWorkitem, and it knows about the rootworkitem so I can find it)

Now this seems dumb I don't want to have to check to make sure my service is in tact everytime I need work done it should be done already, or do it when I ask since I should be able to start my JobWorkItem without my service running because if the user doesn't want to look at jobs then why should this service be running and using memory?. So I go looking for a answer and I find "Services on Demand". Wow doesn't that sound nice just what I need.

But still how is my JobServiceAgent going to find out about the offlineBlockBuilder without talking to the JobWorkitem directly?

So whati need is a way to get a reference of a RootWorkItems.Service to a childWorkItems Service?

Any Ideas?

Oh and if someone has tackled this please tell me what your experience with it.
Jul 7, 2006 at 1:58 PM
originally posted by: askew

If I understand your situation accurately, you should look at using the Event Broker publish/subscribe to raise events and listen to them across the CAB between the disparate parts you described.
Jul 8, 2006 at 6:23 AM
originally posted by: JKraft4PIT

I could do use event publication/subscription.

But what I really need is the childworkitems service(JobService) to have a dependency on the parentworkitem service (offlineBlockBuilder).

And I am not sure how I could go about doing this.
Jul 8, 2006 at 6:42 AM
originally posted by: ChrisHolmes

So, if I get this right, you have the Offline stuff as a service, and the Job stuff as a service, and the Job stuff has a dependency on the Offline service.

You should be able to have one service dependent on another. The CAB Dependency Injection system should automatically wire up that dependency if you declare it.

Do you have an ServiceDependency declared for the JobServiceAgent? Should look something like this:

public class JobServiceAgent{

private ObjectBlockBuilder builder;

public JobServiceAgent(ServiceDependecy ObjectBlockBuilder builder){

this.builder = builder;
}
}


Then when you create the new JobServiceAgent, the DI framework automatically handles the injection:

JobServiceAgent jsAgent = Services.AddNew<JobServiceAgent>();

I tested this out with a couple classes that just print strings and it does work.
Jul 8, 2006 at 7:10 AM
originally posted by: JKraft4PIT

Thanks I didn't think to put the service injection in the jobService.
Don't know hwy guess to simple a thought.

I will try it thanks.
Jul 8, 2006 at 11:05 AM
originally posted by: ChrisHolmes

Well, it won't inject dependencies if you don't tell it to :-)

Should work. Good luck!