laskoviymishka / MvcDeviceDetector

Enables device detection mechanism for aspnet mvc core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MvcDeviceDetector

Adaptive web site should adjust his behaivior according to current device. Adaptive site should also have preference mechanism, with ability to switch between preferences, not matter for device (like github for example). This could help a lot of developers to build rich and adaptive websites.

Firstly we need to include MvcDeviceDetector package via .

Install-Package MvcDeviceDetector -Pre

Than we should register required service and specify some options: You could just add device detector:

services.AddDeviceDetector();

or you may implement you own IDeviceFactory for device detection. And optionally you may add device switcher (for runtime device changing).

services.AddDeviceSwitcher<CookieSwitcher>();

or

services.AddDeviceSwitcher<UrlSwitcher>();

or implement your own device switcher by implementing interface IDeviceSwitcher

After this configuration new ViewLocationExpanders will be applied and start to search device specific views from prefixes or subfolders. Device would be detected from user agent according to lite device detection mechanism (simillar to http://projects.spring.io/spring-mobile/).

You could also add preference switcher mechanism, to enable switch:

services.AddDeviceSwitcher<UrlSwitcher>(switcherOptions => { }, deviceOptions => { });

If you specify device switcher, you should also map this switcher to some route:

route.MapDeviceSwitcher();

After that, you will have an ability to override default agent detetection with some preference, by calling URL in format: /choose/{device}. Mechanism provide following extensibility point:

  1. Allow developer to change device codes, and aliases
  2. Allow developer to use own device implementation, by adding specific device factory
  3. Allow developer to introduce new device types expect regular tablet and mobile
  4. Allow developer to switch between Switcher mechanism (by default, it should store preference in cookies, but also should be have ability to use URL switcher or whatever machanism that you could implement)
  5. Allow developer to change URL generation rules

For any questions and bug please file an issue. Any contributions highly appreciate.

About

Enables device detection mechanism for aspnet mvc core

License:Other


Languages

Language:HTML 63.4%Language:C# 32.0%Language:PowerShell 2.3%Language:Shell 1.6%Language:Batchfile 0.7%