Fusonic.Extensions.Hosting 11.0.0

Prefix Reserved
dotnet add package Fusonic.Extensions.Hosting --version 11.0.0
                    
NuGet\Install-Package Fusonic.Extensions.Hosting -Version 11.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="11.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fusonic.Extensions.Hosting" Version="11.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Fusonic.Extensions.Hosting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fusonic.Extensions.Hosting --version 11.0.0
                    
#r "nuget: Fusonic.Extensions.Hosting, 11.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.
#:package Fusonic.Extensions.Hosting@11.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fusonic.Extensions.Hosting&version=11.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Fusonic.Extensions.Hosting&version=11.0.0
                    
Install as a Cake Tool

Hosting

Package: Fusonic.Extensions.Hosting

TimedHostedService

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

It has the following behaviour:

  • The first run starts immediately when the host starts.
  • The next run starts after the configured interval has passed since the end of the previous run (default: 15 minutes). Runs never overlap.
    • Example: Interval 15 minutes, the method takes 20 minutes. The runs start at 0, 35 and 70 minutes.
  • Exceptions are logged and do not stop the service. The next run is scheduled as usual.
  • After a successful run, an optional watchdog URI gets called (HTTP GET). That way you can monitor if your service is still running successfully.
  • When the host stops, your method is notified via the provided CancellationToken.
  • Each run resolves your service in a new scope.

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);
}

Register it with AddTimedHostedService<TService>. The first parameter configures the settings, the second calls your method. The extensions are in the namespace Fusonic.Extensions.Hosting, the settings in Fusonic.Extensions.Hosting.TimedHostedService.

Microsoft.Extensions.DependencyInjection

The service gets registered as scoped:

using Fusonic.Extensions.Hosting;

services.AddTimedHostedService<HelloWorldService>(cfg => configuration.Bind("HelloWorld", cfg), (svc, ct) => svc.Run(ct));

SimpleInjector

Use the extension on the AddSimpleInjector options. The service gets registered with the container's default lifestyle and is resolved within an AsyncScopedLifestyle scope per run, so set container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle() if the service has scoped dependencies.

The hosted service requires an IHttpClientFactory, which you have to register yourself with services.AddHttpClient():

using Fusonic.Extensions.Hosting;

var host = Host.CreateDefaultBuilder(args)
    .ConfigureServices((hostContext, services) =>
    {
        services.AddHttpClient();
        services.AddSimpleInjector(container, options =>
        {
            options.AddTimedHostedService<HelloWorldService>(cfg => hostContext.Configuration.Bind("HelloWorld", cfg), (svc, ct) => svc.Run(ct));
        });
    })
    .Build();

host.Services.UseSimpleInjector(container);

Configuration

TimedHostedServiceSettings has two options:

  • Interval: Seconds between the end of a run and the start of the next one. Defaults to 900 (15 minutes). Must be greater than zero.
  • WatchdogUri: URI which is called after each successful run. Defaults to null (no call).

The matching configuration in the appsettings.json could look like the following. All values are optional.

{
    "HelloWorld": {
        "Interval": 300,
        "WatchdogUri": "https://watchdog.example.com/?projectId=12345"
    }
}
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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
11.0.0 0 11/23/2026
10.3.0 84 11/9/2026
10.2.0 96 11/5/2026
10.1.0 354 3/18/2026
10.0.1 162 3/17/2026
10.0.0 303 11/25/2025
10.0.0-rc.2 212 11/24/2025
10.0.0-rc.1 182 9/12/2025
9.5.4 311 8/20/2025
9.5.3 356 3/28/2025
9.5.2 314 1/16/2025
9.5.0 311 10/4/2024
9.4.0 292 9/23/2024
9.3.1 321 9/11/2024
9.3.0 322 9/11/2024
9.2.0 309 8/8/2024
9.2.0-rc.3 158 8/7/2024
9.2.0-rc.2 162 8/5/2024
9.2.0-rc.1 145 8/1/2024
9.1.0 280 7/29/2024
Loading failed