views:

34

answers:

2

I'm learning Composite Application Block and I've hit a rock about services. I have my shell application in its own solution, and of course a test module in its own solution (developed and testing completely independent and external of the shell solution). If I created a service named "Sql Service", would I need to put this in it's own library, so that both the shell, and the module know the types?

If that's the case, then for good practice, should I put the service project in the shell solution, or external just like a module (in it's own solution), even though it's not loaded as a module?

Then, what about references? Should the shell reference this directly, add then add the service? Or load it as a module and add the service?

I have a lot of confusion on where I should create my services, and if I should reference or load as modules..

+1  A: 

If you have a service that you want to expose to two different assemblies, then what you should do is define the interface for that service in a separate assembly and share that between the two. Generally speaking, I always put services in their own assembly (project) and I put the interface definitions to those services in a separate assembly (project).

In the specific case of the CAB I would avoid exposing much of anything to the Shell unless it is absolutely necessary - only if the Shell itself has to use the service would I reference it in the Shell. The Shell should be bare-bones; it exists so that modules can show their own elements to the user. Individual modules can worry about referencing and utilizing the specific services.

As far as solution organization: Generally, when I am working on a CAB application, everything is in one solution. I have rarely had need for separate solutions. Separate projects, yes - but all under one umbrella solution.

Chris Holmes
A: 

In addition to Chris's answer, the only way that your shell would come to know about your service, is if you have a service dependency in the shell on your service and you have added the service to your root workitem.

So in the shell you would have code something like

private ISqlService sqlService;

[ServiceDependency Required=false] public ISqlService SqlService { get { return sqlService; } set { sqlService = value; } }

In the SqlService class (which should be inherited from the WorkItemController class) you would have something like

_rootWorkItem.Services.AddNew();