views:

363

answers:

3

First,Im running a windows service that should contain a lot of funcionality.There will be a business layer and the results comming from this business layer will be sent over WCF to the presentation layer.

I dont know how to structe all this functionality.

So my questions are :

1. Should I create somekind of a Facade pattern class that will cover all the service classes and put this one Facade Class to one ServiceHost. Or just create a ServiceHost instance for every service class?? Like this

host1 = new ServiceHost(typeof(MyService1));
host2 = new ServiceHost(typeof(MyService2));

2.How granular should be my service classes? Per enitity or per aggregate root or per some functionality block ?

This communication will run over net.pipe.

+1  A: 

Let your interfaces be your guide. Define the interfaces you plan to expose through WCF. This will define how many service classes you need, and consequently, how many ServiceHost instances you need.

Matt Davis
+3  A: 

There's an example of running multiple service hosts under a single windows service here: http://thegrenade.blogspot.com/2009/08/hosting-multiple-wcf-services-under.html

And a related question here: http://stackoverflow.com/questions/1308975/can-you-host-multiple-wcf-processes-in-a-single-windows-service

grenade
+1  A: 

One ServiceHost can only host a single service (implementation) class - that's a given, you can't change that.

But a service (implementation) class can implement any number of service contracts (interfaces).

However, living up to the separation of concerns principle, I don't see a lot of compelling reasons to have a humongous "SuperDuperServiceClass" which implements a boat load of service contracts - I like to keep things that have nothing to do with one another separate - makes it easier to manage it in the long run.

What's your reasoning against having a single service host for a single service?

marc_s