Home Exposing .NET MVC Service layer as REST endpoints
Reply: 1

Exposing .NET MVC Service layer as REST endpoints

Arlo Guthrie
1#
Arlo Guthrie Published in 2017-11-14 18:24:16Z

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?

Luis Teijon
2#
Luis Teijon Reply to 2017-11-14 19:52:15Z

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316882 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO