Shyjus.BrowserDetector.AzureFunctions 1.0.0-preview1

This is a prerelease version of Shyjus.BrowserDetector.AzureFunctions.
dotnet add package Shyjus.BrowserDetector.AzureFunctions --version 1.0.0-preview1                
NuGet\Install-Package Shyjus.BrowserDetector.AzureFunctions -Version 1.0.0-preview1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Shyjus.BrowserDetector.AzureFunctions" Version="1.0.0-preview1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Shyjus.BrowserDetector.AzureFunctions --version 1.0.0-preview1                
#r "nuget: Shyjus.BrowserDetector.AzureFunctions, 1.0.0-preview1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

  1. Browser detection
  2. Device type detection
  3. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 110 1/2/2024