What in your opinion is good practice to handle the case where I want to have re-usable and shared logic that collects and returns my data from the database?
For example I have Multi Page Application and one day I decide to make Single Page Application out of it. I don't want to re-write much.
This brings up the question: How should I approach this problem?
- Both types of application talk directly to the exposed WebAPI which in turn talks to some class (like repository) making calls to the database. And then in case of SPA returning the JSON.
- There is a DLL with the logic and only WebAPI project uses this DLL, which probably means there are internal HTTP calls to the API in case of Multi Page Applications and it's the server making these requests.
- Database access is not direct, goes through the service exposing the API, can be hosted on the same server.
Wouldn't it be more expensive approach than the one as shown on the second image below? (because of the HTTP calls instead talking directly to the database)
Multi Page Application doesn't know anything about WebAPI exposed to other clients (desktop, mobile, single page web apps). The repository (logic) class is instead shared with the WebAPI controllers and classic controllers that return View instead of data.
There is a DLL with the logic and both projects depend on this DLL. Means no internal HTTP requests in case of MPA - less expensive?
Direct database access
Which approach should I choose and why? Is the first approach more expensive than the other because of internal HTTP requests?