I want my project's code to be re-usable as well as it is possible. That means let's say that I start with classic MVC application(controllers that return views) and then some day I decide that I want to use Javascript framework like Angular, React, Vue. So I need controllers that return JSON.
I currently have 2 layers (projects) that are responsible for doing different things.
- Data
- my model classes as well as repositories (helper classes that access my db data)
- my DbContext subclass. It is used to communicate with the database.
- IdentityUser and IdentityRole subclasses for different types of users
- API (depends on Data project, more friendly version of DAL - Data Access Layer)
- my controller classes that return JSON for use with other applications (that are not neccesserily webpages, for example mobile app)
Now let's say I want to create 3rd project called MVC, so regular Multiple Page Application that returns views and uses Razor as templating engine.
- MVC
- returns views (depends either on API project or Data project directly, but I don't know which :( )
I was thinking to directly call my API from this project(on the server-side), but as controllers are required to return views (cshtml) it's probably not the option ? and I need to communicate directly with the database and not the API that returns the JSON?
What solution would you recommend?