Fusonic.Extensions.Hosting 8.1.3

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Fusonic.Extensions.Hosting --version 8.1.3
NuGet\Install-Package Fusonic.Extensions.Hosting -Version 8.1.3
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="Fusonic.Extensions.Hosting" Version="8.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fusonic.Extensions.Hosting --version 8.1.3
#r "nuget: Fusonic.Extensions.Hosting, 8.1.3"
#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 Fusonic.Extensions.Hosting as a Cake Addin
#addin nuget:?package=Fusonic.Extensions.Hosting&version=8.1.3

// Install Fusonic.Extensions.Hosting as a Cake Tool
#tool nuget:?package=Fusonic.Extensions.Hosting&version=8.1.3

Hosting

TimedHostedService

If you have a service that should execute every once in a while, for example a sync, you can use TimedHostedService<> for triggering your service. You just have to care about your business logic, not about the hosting logic.

The TimedHostedService<> is a hosted service which executes a method in your service class, repeating after a specified interval.

It has the following behaviour:

  • Execute a method on your service repeatedly
  • The interval between executions can be configured, defaulting at 15 minutes.
  • It ensures, that your method is not called concurrently.
    • If your method takes longer than the interval to execute, it will not be triggered again.
    • Example: Method takes 20 minutes
      • First trigger after 15 minutes sees that your method is still running ⇒ nothing happens
      • Second trigger after 30 minutes sees that your method is not running ⇒ method gets startet again
  • After your method executed successfully, a watchdog URL gets called. That way you can monitor if your service is still running successfully.
    • The URL is optional
  • When the program gets stopped, your service is kindly notified to shutdown with the provided CancellationToken.

Setup

Given the following Service:

public class HelloWorldService
{
    public Task Run(CancellationToken cancellationToken)
    {
        Console.WriteLine("Hello world");
        return LongRunningLogic(cancellationToken);
    }

    private Task LongRunningLogic(CancellationToken cancellationToken) 
        => Task.Delay(10_000_000, cancellationToken);
}

When configuring your host you can register timed services in the AddSimpleInjector-part. There's an extension to the options AddTimedHostedService<TService>. It has a parameter for the configuration and one to call your method.
The configuration only consists of two options:

  • Interval: The interval in seconds in which your method should be executed. Defaults to 900 (15 minutes).
  • WatchdogUri: The URI which should be called after a successfull run. Defaults to null.

Example configuration:

var host = new HostBuilder()
   .ConfigureHostConfiguration(/* ... */)
   .ConfigureServices((hostContext, services) => {
       // Some config

       services.AddSimpleInjector(container, options =>
       {
           // Add HelloWorldService
           // Configuration is in the appsettings-section "HelloWorld"
           // We want to run our service method "Run" and we react to the provided cancellation token in there.
           options.AddTimedHostedService<HelloWorldService>(cfg => hostContext.Configuration.Bind("HelloWorld", cfg), (svc, ct) => svc.Run(ct));
       });
       // Some more config
    })
   .Build()

The according configuration in the appettings for this example could look like the following. Note that all parameters are optional and the config could also be injected via EnvironmentVariables, depending on your HostConfiguration.

{
    "HelloWorld": {
        "Interval": 300,
        "WatchdogUrl": "https://watchdog.fusonic.net/?projectId=12345"
    }
}
Product Compatible and additional computed target framework versions.
.NET 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
9.0.0-preview.1 33 4/5/2024
8.1.3 78 3/27/2024
8.1.2 76 3/27/2024
8.1.1 79 3/1/2024
8.1.0 101 1/26/2024
8.0.1 109 12/18/2023
8.0.1-rc.2 76 12/7/2023
8.0.1-rc.1 61 12/6/2023
8.0.0 148 11/21/2023
8.0.0-preview1 59 10/4/2023
7.4.0 69 1/25/2024
7.3.0 92 10/11/2023
7.2.1-rc.1 76 8/28/2023
7.2.0 202 6/28/2023
7.2.0-alpha.1 65 6/27/2023
7.1.2 194 5/25/2023
7.1.1 511 4/3/2023
7.1.1-rc.2 71 3/30/2023
7.1.1-rc.1 71 3/30/2023
7.1.0 338 2/28/2023
7.1.0-rc.1 81 2/20/2023
7.0.4-rc.5 87 2/23/2023
7.0.4-rc.4 86 2/23/2023
7.0.4-rc.3 81 2/23/2023
7.0.4-rc.2 86 2/22/2023
7.0.4-rc.1 83 2/16/2023
7.0.3 326 2/16/2023
7.0.2 246 2/9/2023
7.0.2-rc.1 96 2/2/2023
7.0.1 486 1/26/2023
7.0.0 272 1/24/2023
7.0.0-preview1 142 7/18/2022
7.0.0-beta.9 98 1/24/2023
7.0.0-beta.8 88 1/23/2023
7.0.0-beta.7 90 1/23/2023
7.0.0-beta.6 85 1/23/2023
7.0.0-beta.5 92 1/23/2023
7.0.0-beta.4 92 1/19/2023
7.0.0-beta.3 87 1/17/2023
7.0.0-beta.2 92 1/11/2023
7.0.0-beta.1 76 11/24/2022
6.2.2 889 9/20/2022
6.2.2-rc.1 114 9/19/2022
6.2.1 1,019 5/4/2022
6.2.0 413 4/21/2022
6.2.0-rc.2 114 4/21/2022
6.2.0-rc.1 113 4/20/2022
6.1.1 637 3/1/2022
6.1.0 514 2/10/2022
6.1.0-rc.3 113 2/10/2022
6.1.0-rc.2 111 2/10/2022
6.1.0-rc.1 113 2/9/2022
6.0.3 689 1/18/2022
6.0.2 257 1/10/2022
6.0.1 265 12/16/2021
6.0.0 497 12/13/2021
6.0.0-rc.6 141 12/6/2021
6.0.0-rc.5 340 12/6/2021
6.0.0-rc.4 479 12/6/2021
6.0.0-rc.3 384 12/6/2021
6.0.0-rc.2 337 12/6/2021
6.0.0-rc.1 418 11/15/2021
5.4.0 468 10/13/2021
5.3.0 324 9/23/2021
5.3.0-rc.1 329 9/17/2021
5.2.0 1,355 5/20/2021
5.2.0-rcjh.6 180 5/19/2021
5.2.0-rcjh.5 139 5/19/2021
5.2.0-rcjh.4 163 5/19/2021
5.2.0-rcjh.3 136 5/19/2021
5.2.0-rcjh.2 128 4/12/2021
5.2.0-rcjh.1 133 4/12/2021
5.1.3 311 5/19/2021
5.1.2 622 3/26/2021
5.1.1 750 1/13/2021
5.1.0 729 12/16/2020