Fusonic.Extensions.Hosting 9.0.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Fusonic.Extensions.Hosting --version 9.0.0                
NuGet\Install-Package Fusonic.Extensions.Hosting -Version 9.0.0                
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="9.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fusonic.Extensions.Hosting --version 9.0.0                
#r "nuget: Fusonic.Extensions.Hosting, 9.0.0"                
#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=9.0.0

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

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.5.0 83 10/4/2024
9.4.0 83 9/23/2024
9.3.1 115 9/11/2024
9.3.0 116 9/11/2024
9.2.0 96 8/8/2024
9.2.0-rc.3 47 8/7/2024
9.2.0-rc.2 33 8/5/2024
9.2.0-rc.1 43 8/1/2024
9.1.0 74 7/29/2024
9.0.0 99 7/17/2024
9.0.0-preview.2 48 6/13/2024
9.0.0-preview.1 59 4/5/2024
8.1.3 139 3/27/2024
8.1.2 106 3/27/2024
8.1.1 112 3/1/2024
8.1.0 130 1/26/2024
8.0.1 136 12/18/2023
8.0.1-rc.2 88 12/7/2023
8.0.1-rc.1 71 12/6/2023
8.0.0 177 11/21/2023
8.0.0-preview1 72 10/4/2023
7.4.0 98 1/25/2024
7.3.0 122 10/11/2023
7.2.1-rc.1 87 8/28/2023
7.2.0 226 6/28/2023
7.2.0-alpha.1 76 6/27/2023
7.1.2 220 5/25/2023
7.1.1 543 4/3/2023
7.1.1-rc.2 84 3/30/2023
7.1.1-rc.1 82 3/30/2023
7.1.0 353 2/28/2023
7.1.0-rc.1 93 2/20/2023
7.0.4-rc.5 97 2/23/2023
7.0.4-rc.4 96 2/23/2023
7.0.4-rc.3 91 2/23/2023
7.0.4-rc.2 97 2/22/2023
7.0.4-rc.1 94 2/16/2023
7.0.3 355 2/16/2023
7.0.2 274 2/9/2023
7.0.2-rc.1 112 2/2/2023
7.0.1 513 1/26/2023
7.0.0 298 1/24/2023
7.0.0-preview1 165 7/18/2022
7.0.0-beta.9 111 1/24/2023
7.0.0-beta.8 99 1/23/2023
7.0.0-beta.7 100 1/23/2023
7.0.0-beta.6 96 1/23/2023
7.0.0-beta.5 103 1/23/2023
7.0.0-beta.4 104 1/19/2023
7.0.0-beta.3 99 1/17/2023
7.0.0-beta.2 100 1/11/2023
7.0.0-beta.1 86 11/24/2022
6.2.2 919 9/20/2022
6.2.2-rc.1 125 9/19/2022
6.2.1 1,048 5/4/2022
6.2.0 436 4/21/2022
6.2.0-rc.2 126 4/21/2022
6.2.0-rc.1 126 4/20/2022
6.1.1 663 3/1/2022
6.1.0 540 2/10/2022
6.1.0-rc.3 124 2/10/2022
6.1.0-rc.2 120 2/10/2022
6.1.0-rc.1 122 2/9/2022
6.0.3 714 1/18/2022
6.0.2 284 1/10/2022
6.0.1 290 12/16/2021
6.0.0 519 12/13/2021
6.0.0-rc.6 151 12/6/2021
6.0.0-rc.5 349 12/6/2021
6.0.0-rc.4 488 12/6/2021
6.0.0-rc.3 393 12/6/2021
6.0.0-rc.2 346 12/6/2021
6.0.0-rc.1 429 11/15/2021
5.4.0 493 10/13/2021
5.3.0 347 9/23/2021
5.3.0-rc.1 338 9/17/2021
5.2.0 1,383 5/20/2021
5.2.0-rcjh.6 190 5/19/2021
5.2.0-rcjh.5 147 5/19/2021
5.2.0-rcjh.4 174 5/19/2021
5.2.0-rcjh.3 146 5/19/2021
5.2.0-rcjh.2 138 4/12/2021
5.2.0-rcjh.1 141 4/12/2021
5.1.3 336 5/19/2021
5.1.2 650 3/26/2021
5.1.1 777 1/13/2021
5.1.0 753 12/16/2020