mvc 4 web api for multiple applications

asp.net-mvc, asp.net-mvc-4, asp.net-web-api

Solution

You can make use of Areas to manage your child apps in the parent one. Please follow steps answered in the question below to create areas in your project

How to Configure Areas in ASP.NET MVC3

For handling Api requests to areas, you need to have two routes in the area registration.

  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 for reaching api controller in the area and second one for regular ones.

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

The above link explains more on this.

By this way you can separate your child apps and organize your functions, models views(if any) in the parent project.

Problem

My mvc 4 application exposes an API layer for 3 different child applications. I am using a single api controller for all the three child apps. All these three apps uses the parent app DB. I would like to know if i am doing anything wrong with this. Also, as the app develops, the api controller is becoming heavy. Is there any good way by which i can manage the child app in the parent app project?.

Original source