Reputation: 1234
I have a .NET MVC application with a service layer that we inject using Unity into the controllers to separate view logic from business logic. Is there any way to expose the same service layer methods as REST endpoints so that other applications could use our service layer as a REST API, while still using the service layer in our monolithic application?
Are there any examples of someone doing this?
Upvotes: 0
Views: 493
Reputation: 4899
In that case, you can create a separated project using ASP.Net Web Api.
Using Web Api, you should be able to inject your services into your controllers and call those Rest Services from your MVC application as well as from any other application (mobile, etc).
You can also consider, in case you are using EF, creating a separate project(layer) for your repository and inject the EF Context
into your repositories, the repositories into your services layer and your services into your controllers.
In my personal projects, I call the services layer only from my WEB API project and never from my MVC application. The MVC will use the services layer only through your REST Services.
Upvotes: 1