Fusonic.Extensions.Hosting
9.5.0
Prefix Reserved
dotnet add package Fusonic.Extensions.Hosting --version 9.5.0
NuGet\Install-Package Fusonic.Extensions.Hosting -Version 9.5.0
<PackageReference Include="Fusonic.Extensions.Hosting" Version="9.5.0" />
paket add Fusonic.Extensions.Hosting --version 9.5.0
#r "nuget: Fusonic.Extensions.Hosting, 9.5.0"
// Install Fusonic.Extensions.Hosting as a Cake Addin #addin nuget:?package=Fusonic.Extensions.Hosting&version=9.5.0 // Install Fusonic.Extensions.Hosting as a Cake Tool #tool nuget:?package=Fusonic.Extensions.Hosting&version=9.5.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 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 | 96 | 10/4/2024 |
9.4.0 | 98 | 9/23/2024 |
9.3.1 | 126 | 9/11/2024 |
9.3.0 | 125 | 9/11/2024 |
9.2.0 | 105 | 8/8/2024 |
9.2.0-rc.3 | 54 | 8/7/2024 |
9.2.0-rc.2 | 39 | 8/5/2024 |
9.2.0-rc.1 | 50 | 8/1/2024 |
9.1.0 | 83 | 7/29/2024 |
9.0.0 | 108 | 7/17/2024 |
9.0.0-preview.2 | 53 | 6/13/2024 |
9.0.0-preview.1 | 65 | 4/5/2024 |
8.1.3 | 147 | 3/27/2024 |
8.1.2 | 114 | 3/27/2024 |
8.1.1 | 119 | 3/1/2024 |
8.1.0 | 137 | 1/26/2024 |
8.0.1 | 144 | 12/18/2023 |
8.0.1-rc.2 | 93 | 12/7/2023 |
8.0.1-rc.1 | 76 | 12/6/2023 |
8.0.0 | 184 | 11/21/2023 |
8.0.0-preview1 | 78 | 10/4/2023 |
7.4.0 | 109 | 1/25/2024 |
7.3.0 | 129 | 10/11/2023 |
7.2.1-rc.1 | 92 | 8/28/2023 |
7.2.0 | 233 | 6/28/2023 |
7.2.0-alpha.1 | 82 | 6/27/2023 |
7.1.2 | 228 | 5/25/2023 |
7.1.1 | 550 | 4/3/2023 |
7.1.1-rc.2 | 89 | 3/30/2023 |
7.1.1-rc.1 | 87 | 3/30/2023 |
7.1.0 | 360 | 2/28/2023 |
7.1.0-rc.1 | 98 | 2/20/2023 |
7.0.4-rc.5 | 102 | 2/23/2023 |
7.0.4-rc.4 | 103 | 2/23/2023 |
7.0.4-rc.3 | 96 | 2/23/2023 |
7.0.4-rc.2 | 102 | 2/22/2023 |
7.0.4-rc.1 | 99 | 2/16/2023 |
7.0.3 | 362 | 2/16/2023 |
7.0.2 | 281 | 2/9/2023 |
7.0.2-rc.1 | 117 | 2/2/2023 |
7.0.1 | 520 | 1/26/2023 |
7.0.0 | 305 | 1/24/2023 |
7.0.0-preview1 | 170 | 7/18/2022 |
7.0.0-beta.9 | 116 | 1/24/2023 |
7.0.0-beta.8 | 104 | 1/23/2023 |
7.0.0-beta.7 | 105 | 1/23/2023 |
7.0.0-beta.6 | 101 | 1/23/2023 |
7.0.0-beta.5 | 108 | 1/23/2023 |
7.0.0-beta.4 | 109 | 1/19/2023 |
7.0.0-beta.3 | 104 | 1/17/2023 |
7.0.0-beta.2 | 105 | 1/11/2023 |
7.0.0-beta.1 | 93 | 11/24/2022 |
6.2.2 | 926 | 9/20/2022 |
6.2.2-rc.1 | 130 | 9/19/2022 |
6.2.1 | 1,055 | 5/4/2022 |
6.2.0 | 443 | 4/21/2022 |
6.2.0-rc.2 | 131 | 4/21/2022 |
6.2.0-rc.1 | 131 | 4/20/2022 |
6.1.1 | 670 | 3/1/2022 |
6.1.0 | 547 | 2/10/2022 |
6.1.0-rc.3 | 129 | 2/10/2022 |
6.1.0-rc.2 | 125 | 2/10/2022 |
6.1.0-rc.1 | 127 | 2/9/2022 |
6.0.3 | 721 | 1/18/2022 |
6.0.2 | 291 | 1/10/2022 |
6.0.1 | 297 | 12/16/2021 |
6.0.0 | 526 | 12/13/2021 |
6.0.0-rc.6 | 156 | 12/6/2021 |
6.0.0-rc.5 | 354 | 12/6/2021 |
6.0.0-rc.4 | 493 | 12/6/2021 |
6.0.0-rc.3 | 398 | 12/6/2021 |
6.0.0-rc.2 | 351 | 12/6/2021 |
6.0.0-rc.1 | 434 | 11/15/2021 |
5.4.0 | 500 | 10/13/2021 |
5.3.0 | 354 | 9/23/2021 |
5.3.0-rc.1 | 343 | 9/17/2021 |
5.2.0 | 1,390 | 5/20/2021 |
5.2.0-rcjh.6 | 195 | 5/19/2021 |
5.2.0-rcjh.5 | 154 | 5/19/2021 |
5.2.0-rcjh.4 | 179 | 5/19/2021 |
5.2.0-rcjh.3 | 151 | 5/19/2021 |
5.2.0-rcjh.2 | 143 | 4/12/2021 |
5.2.0-rcjh.1 | 146 | 4/12/2021 |
5.1.3 | 343 | 5/19/2021 |
5.1.2 | 657 | 3/26/2021 |
5.1.1 | 784 | 1/13/2021 |
5.1.0 | 760 | 12/16/2020 |