Mvc 4 web api for multiple applications

My mvc 4 application provides an API layer for 3 different child applications. I use one api controller for all three child applications. All three of these applications use the parent DB application.

I would like to know that I am doing something wrong with this. In addition, as the application evolves, the api controller becomes heavy. Is there a good way that I can manage a child application in a parent application project ?.

+5
source share
2 answers

You can use Scopes to manage child applications in the parent. Please follow the steps in the question below to create areas in your project.

How to configure scopes in ASP.NET MVC3

To process Api requests for regions, you need to have two routes in registering the region.

  public override void RegisterArea(AreaRegistrationContext context)
    {
        context.Routes.MapHttpRoute(
            name: "Area_Name_Api",
            routeTemplate: "Area_Name/api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        context.MapRoute(
            "Area_Name_default",
            "Area_Name/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }

The first route is designed to reach the api controller in the area, and the second for the usual ones.

http://blogs.infosupport.com/asp-net-mvc-4-rc-getting-webapi-and-areas-to-play-nicely/

The link above explains more.

Thus, you can separate child applications and organize their functions, view models (if any) in the parent project.

+5
source

You can handle child applications under different web api controllers.

+4
source

All Articles