GithubHelp home page GithubHelp logo

tuyndv / responsive Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kostavlev/responsive

0.0 2.0 0.0 428 KB

ASP.NET Core Responsive middleware for routing base upon request client device detection to specific view

License: GNU General Public License v3.0

Batchfile 0.65% PowerShell 14.27% Shell 15.80% C# 69.28%

responsive's Introduction

ASP.NET Core Responsive

Build status NuGet Pre Release Pre-Release (Still in development)

ASP.NET Core Responsive

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

Implement a strategy to select the device for each request

Configuring Responsive

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 to Suffix. 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 to Subfolder. In this sample view Responsive is based on the view file subfolder.

    Ex views/[controller]/[action]/mobile/index.cshtml

Responsive Middleware

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.

Related projects

responsive's People

Contributors

wangkanai avatar kostavlev avatar

Watchers

James Cloos avatar Tuyn Doan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.