Please help me to figure out how to refactor my project with messed layers. I have monolith ASP.net MVC project with API controllers in it and typescript which most API calls are coming from. My biggest problem is that with current design I'm not able to reuse my code and unit test it properly. The only think I can do is do an integration test of whole api endpoint, which is not nice. My api controllers are really bulky like 50/100 lines of code per endpoint, bulkiest controllers has like 4k line of code. I need some help to point me out which direction I should choose to code new features to be able to unit test my business logic and reuse my code.
Most of my API endpoints looks like that:
public IEnumerable<ModelADto> GetComplexData(object[] someQueryParameters)
{
// parameter validation
// Getting data from DB table ModelA using complex LINQ queries and someQueryParameters
// Getting data from diffrent DB table ModelB using complex LINQ queries and someQueryParameters
....
// **doing some business logic** using above data to get List of ModelA objects
//Mapping List<ModelA> to List<ModelADto>
// returning above List of ModelADto objects
}
I didn't find any good pattern to solve this problem, repository&service pattern doesn't fit here for me, because one API controller will have like 1-15 different services/repositories in it or I'm just missing something and this is the way I should follow?
Aucun commentaire:
Enregistrer un commentaire