I'm having serious doubts about the design for my Web application.
I wanted to separate the business logic from the interface so I made a Web API that handles all the requests to the database.
It's an ASP.NET Web API with Entity framework and a unit of work and generic repository pattern. So far, everything is good.
Where I need help is I can't figure out an efficient way of sharing objects between the API and the application.
I don't want to serialize directly the entity object, I thought it would be a bad practice because if the entity model changes, I could end up with serializing large objects for no reason.
How it's implemented now
Because my interface is ASP.NET Web application in C# and my API is in C#, I made a common library with the definition of all my classes I want to share between them.
I know that solution won't work when I will develop an android app, I will have to create my classes again in Java but that's not my biggest problem.
The problem is I feel like I'm always converting my objects.
Here's an example of my work flow :
I start with a model with all the objects and the data annotations for my form then user would POST that model to a controller.
In the controller I have to convert this model to a class in my common library then send that object to my API.
Then a controller in my API catch the call and convert that object to an entity object to update the database.
So I have 3 classes
- The model for the view with all the data annotation for the validation (Client)
- The common library classes to share the objects (DLL)
- The Entity classes (API)
I have a feeling that I do something really wrong. Is there something more elegant? I would like to make sure that I have a good solution for this problem before the project gets too big.