Language: C#
Application Type: .NET Core Web Api
I am designing some Web API end points and services which will be called by these APIs.
After finishing the code for 2 services, I found for similar sequence of operations in 2 methods (eg: GetXXXInfo and GetYYYInfo) in 2 different services.
Operations that takes place in both Service methods:
Method Input/Output: Input/Output UI models resp.
Service gets Input UI model -> Maps it to a Data Contract (Classes we generate based on schema provided by external vendor) -> Sends it to External vendors API -> Retrieves Output Data Contract -> Maps it to Output UI model -> Returns data to Action Method
Design Restrictions: The UI models may or may not have have in common. So base interface might need to be forced. Also We have no control over generated Data Contracts . So they cant have base implementation.
My Goal: Try to bring common service call for different model/contracts. If Action method needs to call service for 2 different inputs in sequence, it should be able to be able to make this Common Service call 2 times for the different inputs.
What I think: I am confused if Factory or Abstract pattern might sound right to remove code duplication and bundling of multiple calls. I found a way of designing a common model by adding an Error Info to the Base Model. But confused about which DP would help my case.
Please advice
Aucun commentaire:
Enregistrer un commentaire