Skip to content

Commit

Permalink
Adding packlage readme (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyju authored Dec 28, 2023
1 parent 06fdc15 commit 3249e7b
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 22 deletions.
4 changes: 3 additions & 1 deletion BrowserDetector.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserDetector.Benchmarks"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserDetector.Net", "src\BrowserDetector.NetCore\BrowserDetector.Net.csproj", "{2E0D3C7A-98AA-475A-816B-3B51EA377C6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserDetector.WebApi", "sample\BrowserDetector.WebApi\BrowserDetector.WebApi.csproj", "{6369627B-5878-4CFE-A996-859D8663603C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserDetector.WebApi", "sample\BrowserDetector.WebApi\BrowserDetector.WebApi.csproj", "{6369627B-5878-4CFE-A996-859D8663603C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{31BD75C3-015A-4308-9B08-07786C191BAC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,14 @@ Install the [BrowserDetector nuget package](https://www.nuget.org/packages/Shyju
Install-Package Shyjus.BrowserDetector
````

**Step 2:** Enable the browser detection service inside the `ConfigureServices` method of `Startup.cs`.
**Step 2:** Enable the browser detection service by calling `AddBrowserDetection` method on `IServiceCollection` in your startup code.

````
public void ConfigureServices(IServiceCollection services)
{
// Add browser detection service
services.AddBrowserDetection();
services.AddMvc();
}
services.AddBrowserDetection();
````
**Step 3:** Inject `IBrowserDetector` to your controller class or view file or middleware and access the `Browser` property.

Example usage in controller code
#### Example usage in controller code

````
public class HomeController : Controller
Expand All @@ -91,7 +85,7 @@ public class HomeController : Controller
}
````

Example usage in view code
#### Example usage in view code

````
@inject Shyjus.BrowserDetection.IBrowserDetector browserDetector
Expand All @@ -103,7 +97,7 @@ Example usage in view code
````

Example usage in custom middlware
#### Example usage in custom middleware

You can inject the `IBrowserDetector` to the `InvokeAsync` method.

Expand Down
95 changes: 95 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

# BrowserDetector

Browser detection capabilities for asp.net core.



This library does

1. Browser detection
2. Device type detection
3. Operating System detection

**Step 1:**
Install the [BrowserDetector nuget package](https://www.nuget.org/packages/Shyjus.BrowserDetector/)


````
Install-Package Shyjus.BrowserDetector
````

**Step 2:** Enable the browser detection service by calling `AddBrowserDetection` method on `IServiceCollection` in your startup code.

````
services.AddBrowserDetection();
````
**Step 3:** Inject `IBrowserDetector` to your controller class or view file or middleware and access the `Browser` property.

### Example usage in controller code

````
public class HomeController : Controller
{
private readonly IBrowserDetector browserDetector;
public HomeController(IBrowserDetector browserDetector)
{
this.browserDetector = browserDetector;
}
public IActionResult Index()
{
var browser = this.browserDetector.Browser;
// Use browser object as needed.
return View();
}
}
````

### Example usage in view code

````
@inject Shyjus.BrowserDetection.IBrowserDetector browserDetector
<h2> @browserDetector.Browser.Name </h2>
<h3> @browserDetector.Browser.Version </h3>
<h3> @browserDetector.Browser.OS </h3>
<h3> @browserDetector.Browser.DeviceType </h3>
````

### Example usage in custom middleware

You can inject the `IBrowserDetector` to the `InvokeAsync` method.

````
public class MyCustomMiddleware
{
private RequestDelegate next;
public MyCustomMiddleware(RequestDelegate next)
{
this.next = next;
}
public async Task InvokeAsync(HttpContext httpContext, IBrowserDetector browserDetector)
{
var browser = browserDetector.Browser;
if (browser.Type == BrowserType.Edge)
{
await httpContext.Response.WriteAsync("Have you tried the new chromuim based edge ?");
}
else
{
await this.next.Invoke(httpContext);
}
}
}
````

### Interpreting the `Name` value returned by `IBrowser.Name`

* Firefox - Firefox browser.
* EdgeChromium - The new Chromium based Microsoft Edge browser.
* Edge - The legacy Edge browser.
* Safari - The Safari browser.
* Chrome - The Chrome browser.
23 changes: 13 additions & 10 deletions src/BrowserDetector.NetCore/BrowserDetector.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<PackageId>Shyjus.BrowserDetector</PackageId>
<AssemblyName>Shyjus.BrowserDetector</AssemblyName>
<RootNamespace>Shyjus.BrowserDetector</RootNamespace>
<Authors>Shyju Krishnankutty</Authors>
<Description>Browser detection, device detection and operating system detection capabilities in asp.net core.</Description>
<RepositoryUrl>https://github.com/kshyju/BrowserDetector</RepositoryUrl>
<PackageTags>BrowserDetection BrowserCapabilities BrowserDetectionASP.NETCore HttpContext.Request.Browser DeviceDetection</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.1-preview1</Version>
<PackageId>Shyjus.BrowserDetector</PackageId>
<AssemblyName>Shyjus.BrowserDetector</AssemblyName>
<RootNamespace>Shyjus.BrowserDetector</RootNamespace>
<Authors>Shyju Krishnankutty</Authors>
<Description>Browser detection, device detection and operating system detection capabilities in asp.net core.</Description>
<RepositoryUrl>https://github.com/kshyju/BrowserDetector</RepositoryUrl>
<PackageTags>BrowserDetection BrowserCapabilities BrowserDetectionASP.NETCore HttpContext.Request.Browser DeviceDetection</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<Version>2.0.1-preview1</Version>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\docs\readme.md" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>

0 comments on commit 3249e7b

Please sign in to comment.