Fusonic.Extensions.Hosting
9.2.0-rc.3
Prefix Reserved
See the version list below for details.
dotnet add package Fusonic.Extensions.Hosting --version 9.2.0-rc.3
NuGet\Install-Package Fusonic.Extensions.Hosting -Version 9.2.0-rc.3
<PackageReference Include="Fusonic.Extensions.Hosting" Version="9.2.0-rc.3" />
paket add Fusonic.Extensions.Hosting --version 9.2.0-rc.3
#r "nuget: Fusonic.Extensions.Hosting, 9.2.0-rc.3"
// Install Fusonic.Extensions.Hosting as a Cake Addin #addin nuget:?package=Fusonic.Extensions.Hosting&version=9.2.0-rc.3&prerelease // Install Fusonic.Extensions.Hosting as a Cake Tool #tool nuget:?package=Fusonic.Extensions.Hosting&version=9.2.0-rc.3&prerelease
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 tonull
.
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 | Versions 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. |
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.0)
- SimpleInjector (>= 5.4.2)
- SimpleInjector.Integration.GenericHost (>= 5.5.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 |
---|---|---|
9.5.0 | 92 | 10/4/2024 |
9.4.0 | 88 | 9/23/2024 |
9.3.1 | 120 | 9/11/2024 |
9.3.0 | 121 | 9/11/2024 |
9.2.0 | 101 | 8/8/2024 |
9.2.0-rc.3 | 50 | 8/7/2024 |
9.2.0-rc.2 | 36 | 8/5/2024 |
9.2.0-rc.1 | 46 | 8/1/2024 |
9.1.0 | 79 | 7/29/2024 |
9.0.0 | 104 | 7/17/2024 |
9.0.0-preview.2 | 51 | 6/13/2024 |
9.0.0-preview.1 | 62 | 4/5/2024 |
8.1.3 | 144 | 3/27/2024 |
8.1.2 | 111 | 3/27/2024 |
8.1.1 | 117 | 3/1/2024 |
8.1.0 | 135 | 1/26/2024 |
8.0.1 | 141 | 12/18/2023 |
8.0.1-rc.2 | 91 | 12/7/2023 |
8.0.1-rc.1 | 74 | 12/6/2023 |
8.0.0 | 182 | 11/21/2023 |
8.0.0-preview1 | 75 | 10/4/2023 |
7.4.0 | 105 | 1/25/2024 |
7.3.0 | 127 | 10/11/2023 |
7.2.1-rc.1 | 90 | 8/28/2023 |
7.2.0 | 231 | 6/28/2023 |
7.2.0-alpha.1 | 79 | 6/27/2023 |
7.1.2 | 225 | 5/25/2023 |
7.1.1 | 548 | 4/3/2023 |
7.1.1-rc.2 | 87 | 3/30/2023 |
7.1.1-rc.1 | 85 | 3/30/2023 |
7.1.0 | 358 | 2/28/2023 |
7.1.0-rc.1 | 96 | 2/20/2023 |
7.0.4-rc.5 | 100 | 2/23/2023 |
7.0.4-rc.4 | 101 | 2/23/2023 |
7.0.4-rc.3 | 94 | 2/23/2023 |
7.0.4-rc.2 | 100 | 2/22/2023 |
7.0.4-rc.1 | 97 | 2/16/2023 |
7.0.3 | 360 | 2/16/2023 |
7.0.2 | 279 | 2/9/2023 |
7.0.2-rc.1 | 115 | 2/2/2023 |
7.0.1 | 518 | 1/26/2023 |
7.0.0 | 303 | 1/24/2023 |
7.0.0-preview1 | 168 | 7/18/2022 |
7.0.0-beta.9 | 114 | 1/24/2023 |
7.0.0-beta.8 | 102 | 1/23/2023 |
7.0.0-beta.7 | 103 | 1/23/2023 |
7.0.0-beta.6 | 99 | 1/23/2023 |
7.0.0-beta.5 | 106 | 1/23/2023 |
7.0.0-beta.4 | 107 | 1/19/2023 |
7.0.0-beta.3 | 102 | 1/17/2023 |
7.0.0-beta.2 | 103 | 1/11/2023 |
7.0.0-beta.1 | 91 | 11/24/2022 |
6.2.2 | 924 | 9/20/2022 |
6.2.2-rc.1 | 128 | 9/19/2022 |
6.2.1 | 1,053 | 5/4/2022 |
6.2.0 | 441 | 4/21/2022 |
6.2.0-rc.2 | 129 | 4/21/2022 |
6.2.0-rc.1 | 129 | 4/20/2022 |
6.1.1 | 668 | 3/1/2022 |
6.1.0 | 545 | 2/10/2022 |
6.1.0-rc.3 | 127 | 2/10/2022 |
6.1.0-rc.2 | 123 | 2/10/2022 |
6.1.0-rc.1 | 125 | 2/9/2022 |
6.0.3 | 719 | 1/18/2022 |
6.0.2 | 289 | 1/10/2022 |
6.0.1 | 295 | 12/16/2021 |
6.0.0 | 524 | 12/13/2021 |
6.0.0-rc.6 | 154 | 12/6/2021 |
6.0.0-rc.5 | 352 | 12/6/2021 |
6.0.0-rc.4 | 491 | 12/6/2021 |
6.0.0-rc.3 | 396 | 12/6/2021 |
6.0.0-rc.2 | 349 | 12/6/2021 |
6.0.0-rc.1 | 432 | 11/15/2021 |
5.4.0 | 498 | 10/13/2021 |
5.3.0 | 352 | 9/23/2021 |
5.3.0-rc.1 | 341 | 9/17/2021 |
5.2.0 | 1,388 | 5/20/2021 |
5.2.0-rcjh.6 | 193 | 5/19/2021 |
5.2.0-rcjh.5 | 152 | 5/19/2021 |
5.2.0-rcjh.4 | 177 | 5/19/2021 |
5.2.0-rcjh.3 | 149 | 5/19/2021 |
5.2.0-rcjh.2 | 141 | 4/12/2021 |
5.2.0-rcjh.1 | 144 | 4/12/2021 |
5.1.3 | 341 | 5/19/2021 |
5.1.2 | 655 | 3/26/2021 |
5.1.1 | 782 | 1/13/2021 |
5.1.0 | 758 | 12/16/2020 |