Like the previous post, I have introduced a Workspace for Web Mvc and along with the post, AzureNotes Module was provided as an example.
Now in this post, I would like to update you the new version 1.0.5 of HBD.Mef.Mvc. From this version, it will support the WebApi technology that allows developing a similar Workspace for Web API.
The HBD.Api.Shell
Similarly to HBD.Mvc.Shell, the HBD.Api.Shell is the Workspace allowing to develop a WebApi module in the different project and deploy to the Workspace lately.
Develop a WebApi module is simpler than develop a module for Wb Mvc because WebApi doesn’t have any resources (views, CSS files, and JavaScript files) other than controllers. Hence, deployment a module into the Shell is just copying the binaries and config files only.
To simplify the life, I have provided a general routing for all Modules including the Workspace as below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public static class WebApiConfig { private const string ShellName = "Shell"; public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( "DefaultApi", "api/{area}/{controller}/{id}", new {area = ShellName, controller = "About", id = RouteParameter.Optional} ); } } |
This route is applying for all modules and all controllers. Hence, the pathway to access to a controller is api/{area}/{controller}{id} which {area} is Module’s name, {controller} is the controller name and {id} is optional.
The module registration also simplified instead of providing the Module Name and custom routing. Promptly with API module requires the name only. Below is sample code to register an API module.
1 2 3 4 5 6 |
public class AzureNoteApiRegister : MefApiRegistration { public override string AreaName => "AzureNote"; } |
The HBD.Mef.Mvc will base on the registered named and select the appropriate controller for the request. If there is no controller found for an appropriate request the HttpResponseException with 404 status code will be thrown.

Please note that this registration is for Api modules only. There is nothing changed on the Mvc module registration that had been introduced on the previous post.
The AzureNoteApi
I would like to show you a similar module for HBD.Api.Shell called AzureNoteApi; this module is just exposing all actions of AzureNote in the previous post as WebApi. Below is the details information the Apis. You can use Postman to try out with my live demo.
Live Demo
Sorry the Azure subscription had been expired
The HBD.Api.Shell is also published on to Azure you might have a try by using Postman with the following API.
- HBD.Api.Shell API
1 2 3 4 5 6 7 |
public class AboutController : ApiController { /// Get http://hbdapishell.azurewebsites.net/api/Shell/About [HttpGet] public AboutInfo Get(); } |
- AzureNote API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
public class AboutController : ApiController { /// Get http://hbdapishell.azurewebsites.net/api/AzureNote/About [HttpGet] public string Get(); } public class NotesController : ApiController { /// Get http://hbdapishell.azurewebsites.net/api/AzureNote/Notes [HttpGet] public Task<IList<Note>> Get(); /// Get http://hbdapishell.azurewebsites.net/api/AzureNote/Notes/084cfe33-f487-4ae9-8b28-c2e2566e1e48 [HttpGet] public async Task<Note> Get(string id); /// Post http://hbdapishell.azurewebsites.net/api/AzureNote/Notes /// Create a new Note which body is Json of Note object. [HttpPost] public Task<IHttpActionResult> Post([FromBody] Note note); /// Put http://hbdapishell.azurewebsites.net/api/AzureNote/Notes/084cfe33-f487-4ae9-8b28-c2e2566e1e48 /// Update an existing Note which body is Json of Note object. [HttpPut] public Task<IHttpActionResult> Put(string id, [FromBody] Note note); /// Delete http://hbdapishell.azurewebsites.net/api/AzureNote/Notes/084cfe33-f487-4ae9-8b28-c2e2566e1e48 [HttpDelete] public async Task<IHttpActionResult> Delete(string id); } |
Source Code
The latest source codes had been uploaded to Github you can download here.