Shyjus.BrowserDetector.AzureFunctions
1.0.0-preview1
dotnet add package Shyjus.BrowserDetector.AzureFunctions --version 1.0.0-preview1
NuGet\Install-Package Shyjus.BrowserDetector.AzureFunctions -Version 1.0.0-preview1
<PackageReference Include="Shyjus.BrowserDetector.AzureFunctions" Version="1.0.0-preview1" />
paket add Shyjus.BrowserDetector.AzureFunctions --version 1.0.0-preview1
#r "nuget: Shyjus.BrowserDetector.AzureFunctions, 1.0.0-preview1"
// Install Shyjus.BrowserDetector.AzureFunctions as a Cake Addin #addin nuget:?package=Shyjus.BrowserDetector.AzureFunctions&version=1.0.0-preview1&prerelease // Install Shyjus.BrowserDetector.AzureFunctions as a Cake Tool #tool nuget:?package=Shyjus.BrowserDetector.AzureFunctions&version=1.0.0-preview1&prerelease
Shyjus.BrowserDetector.AzureFunctions
Browser detection capabilities for Azure functions .NET Isolated model.
This library does
- Browser detection
- Device type detection
- Operating System detection
Step 1: Install the BrowserDetector.AzureFunctions nuget package
Install-Package Shyjus.BrowserDetector.AzureFunctions
Step 2: Enable the browser detection service by calling AddBrowserDetection
method on IFunctionsWorkerApplicationBuilder
in your startup code.
using Microsoft.Extensions.Hosting;
using BrowserDetector;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults((b) =>
{
b.AddBrowserDetection();
})
.Build();
host.Run();
Step 3: Inject IBrowserDetector
to your function class e and access the Browser
property.
Example usage
public class Function1
{
private readonly ILogger _logger;
private readonly IBrowserDetector _detector;
public Function1(ILoggerFactory loggerFactory, IBrowserDetector detector)
{
_logger = loggerFactory.CreateLogger<Function1>();
_detector = detector ?? throw new ArgumentNullException(nameof(detector));
}
[Function("Function1")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
var response = req.CreateResponse(HttpStatusCode.OK);
response.WriteString($"Browser: {_detector.Browser?.ToString()}");
return response;
}
}
Example usage in functions middleware
You can get instance of the IBrowserDetector
from FunctionContext.
public sealed class MyFuncMiddleware : IFunctionsWorkerMiddleware
{
public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next)
{
var logger = context.GetLogger<MyFuncMiddleware>();
var browserDetector = context.InstanceServices.GetRequiredService<IBrowserDetector>();
IBrowser? browser = browserDetector.Browser;
logger.LogInformation($"MyFuncMiddleware executing. Browser:{browser?.Name} {browser?.OS}");
await next(context);
}
}
and make sure you register this middleware after enabling the browser detection feature.
using Microsoft.Extensions.Hosting;
using BrowserDetector;
using BrowserDetector.FunctionApp;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults((b) =>
{
b.AddBrowserDetection();
b.UseMiddleware<MyFuncMiddleware>();
})
.Build();
host.Run();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- BrowserDetector.Abstractions (>= 1.0.0)
- BrowserDetector.Core (>= 1.0.0)
- Microsoft.Azure.Functions.Worker.Core (>= 1.16.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
-
net7.0
- BrowserDetector.Abstractions (>= 1.0.0)
- BrowserDetector.Core (>= 1.0.0)
- Microsoft.Azure.Functions.Worker.Core (>= 1.16.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
-
net8.0
- BrowserDetector.Abstractions (>= 1.0.0)
- BrowserDetector.Core (>= 1.0.0)
- Microsoft.Azure.Functions.Worker.Core (>= 1.16.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-preview1 | 112 | 1/2/2024 |