How can I organize a large number of methods in the .NET WCF service?

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 structures and can be easily divided into functional areas. There is only one file that approaches 1K lines of code, and I would like to split it into maintainability. I consider the following:

  • Divide the service file into partial classes. But it will still be one class with lots of code. Although, I think this is really not a problem.
  • Have one class that implements a service interface with standard error handling and ObjectContext creation / destruction, and routes calls to static helper classes. I have done this before, but for some reason it does not seem clean to me.

In addition, it would be better to divide by functional area or by CRUD methods (the group is combined, creates together, etc.).

This should be a very common problem when working 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 the inner static classes.

+6
source share
2 answers

If operations can be grouped by functional area, they must be separate services, because a service like any other class should have a single responsibility = a single functional area.

As a rule, if your service has many operations, the time has come to split it. In addition, more often than not, the WCF service is just a wrapper around some logic, so you can create instances of other classes that wrap your logic, or use static classes in your service operations.

Edit:

In general, I am opposed to using partial classes to break a large class - in my opinion, this does not improve maintainability. When the class is so large that you are looking for a solution to split it into multiple files, this already means that refactoring should have been done a long time ago. In the worst case scenario, when your class does too much, we can call it an anti-pattern: an object of God .

+8
source

For convenience, using partial classes seems like a good option. If they are functionally separated, maintainability improves because you only need to look at one or two of these classes.

The fact that there is another huge class with many methods is not really a problem based on your answers. It must be serviced.

But, to follow @Ladislav, is there any value for you by dividing them into separate services? I did not imagine, otherwise you would have done it.

+2
source

Source: https://habr.com/ru/post/893509/


All Articles