Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good way organize large number of methods in a .NET WCF service?

Tags:

.net

wcf

I am currently working on a WCF service with a large number of methods defined in the interface. Most of these methods are simple CRUD operations with a bit of logic using entity framework, and could be split into functional areas pretty easily. There's only a single file that is approaching 1K lines of code and I would like to split it up for maintainability. I am considering the following:

  • Split the service file into partial classes. But it still would be a single class with a large amount code. Altough, I guess this is really not a problem.
  • Have a single class that implements the service interface with the standard error handling and ObjectContext creation/destruction, but route the calls to static helper classes. I have done this before, but somehow it doesn't feel clean to me.

Also, would it be better to split by functional area, or by CRUD methods (group all gets together, creates together, etc).

This must be a very common issue when dealing with WCF services. What is a good way to organize WCF service methods?

Update

In the end, I decided to pass the service calls to internal static classes.

like image 531
Mas Avatar asked Jul 25 '11 15:07

Mas


2 Answers

If operations can be grouped by functional areas they should be separate services because service as any other class should have single responsibility = single functional area.

Generally if your service has a lot of operations it is time to thing about its splitting. Also most often WCF service is only wrapper around some logic so you can create instances of other classes wrapping your logic or use static classes in your service operations.

Edit:

Generally I'm against using partial classes to break a big class - in my opinion it doesn't improve maintainability. Once a class is so big that you are looking for solution to break it into multiple files it already means that refactoring should have been done long ago. In the worst case when your class is doing really too much we can call it anti pattern: God object.

like image 79
Ladislav Mrnka Avatar answered Oct 13 '22 00:10

Ladislav Mrnka


For maintainability, using partial classes would seem to be a good option. If they are split functionally, then the maintainability is improved becasue you should only need to look at one or two of these classes.

The fact that there is still one huge class with many methods is not really a problem on the basis of your answers. It should be maintainable.

But, to follow @Ladislav, is there any value to you in separating them out into separate services? I assumed not, otherwise you would have done that.

like image 42
Schroedingers Cat Avatar answered Oct 13 '22 00:10

Schroedingers Cat