I accidentally found this topic, but it is curious that I work in my free time to solve the same problem as here as a hobie, because now we have about 300 services at work, and this is growing, and there are basic operations (CRUD) that have the same structure and only modify EntityType, and there are also many custom methods, and I donβt like to repeat this, so I think this is not a bad idea, but I want to take care of some of the problems explained - in my opinion Aaronagut is very good, because now I will think about how to respond to these eschi. also.
Thus, in principle, the concept is the same, only one service (given that a complete solution can be more, but now only one), which processes all types of requests.
So, about the different parameters, I have a method in a service called Execute (Request Request) that receives the request, this request can be a general request object or a user request object, for example CreateRequest or DeleteRequest. A custom request has the properties necessary for this operation, so I can create an ApproveRequest as well. This request contains information about EntityType, the name of the operation declared in the BusinessComponent, and there are other parameters (the request acts like a property bag or dictionary), and the methods of business components are defined as follows: Update (BusinessEntity object) or Approve (Guid orderId, bool anotherParameterHere )
When the call is made, I process the request and extract the information that I mainly need EntityType and OperationName, and then I compare the input parameters in the request object with the expected method parameters, which I get this using reflection too ... and in BaseBusinessComponent I can create a strict BusinessEntity object that the Client will tell, this client inherits from BusinessEntity.
Another important thing is the response, which is processed in the same way as the request, if the request has an appropriate response class (just replace Request by Response), then I create an object of this request and add the values ββreturned by the method in the business component so that I can return property package and copy all the properties into Response, or if it is not a property bag, I assign a value (if the method is not empty) to the general property "Result", and this result can be in my CustomResponse I could override it and read the value and assign every individual the ideal property known in the CustomResponse class (but I haven't done it yet).
Here is an example of code that I can write right now, this is something very important:
AppService service = new AppService(); //Create an order BusinessEntity order = new BusinessEntity("Order"); order["OrderId"] = Guid.NewGuid(); order["CustomerName"] = "Greivin Britton"; CreateRequest request = new CreateRequest(); request.Entity = order; CreateResponse response = (CreateResponse)service.Execute(request); //Create a customer Customer customer = new Customer(); customer.FirstName = "Greivin"; customer.LastName = "Britton"; Request request2 = new Request(); request2.MessageName = "Create"; request.Entity = customer; Response response2 = service.Execute(request2);
To get data using different filters, I may have to create an ExpressionBuilder class or something like that ...