Pre-Release (Still in development)
ASP.NET Core Responsive middleware for routing base upon request client device detection to specific view. Being to target difference client devices with seperation of concern is crucial, due to you can mininize what is sent to the client directly from the service to only what is needed and nothing more. This increase performance and lower bandwidth usage.
Installation - NuGet
PM> install-package Wangkanai.Responsive -pre
Responsive is configured in the ConfigureServices
method:
public void ConfigureServices(IServiceCollection services)
{
// Add responsive services.
services.AddResponsive()
.AddViewSuffix()
.AddViewSubfolder();
// Add framework services.
services.AddMvc();
}
-
AddResponsive()
Adds the Responsive services to the services container. -
AddViewSuffix()
Adds support for device view files toSuffix
. In this sample view Responsive is based on the view file suffix.Ex views/[controller]/[action]/index.mobile.cshtml
-
AddViewSubfolder()
Adds support for device view files toSubfolder
. In this sample view Responsive is based on the view file subfolder.Ex views/[controller]/[action]/mobile/index.cshtml
The current device on a request is set in the Responsive middleware. The Responsive middleware is enabled in the Configure
method of Startup.cs file.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseResponsive();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
UseResponsive()
Add the responsive middleware into the http pipeline. Its will capture the request and resolve the device to responsive services container.