SpawnDev.BackgroundServices 2.0.0

dotnet add package SpawnDev.BackgroundServices --version 2.0.0
                    
NuGet\Install-Package SpawnDev.BackgroundServices -Version 2.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="SpawnDev.BackgroundServices" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SpawnDev.BackgroundServices" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SpawnDev.BackgroundServices" />
                    
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 SpawnDev.BackgroundServices --version 2.0.0
                    
#r "nuget: SpawnDev.BackgroundServices, 2.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 SpawnDev.BackgroundServices@2.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=SpawnDev.BackgroundServices&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SpawnDev.BackgroundServices&version=2.0.0
                    
Install as a Cake Tool

SpawnDev.BackgroundServices

NuGet

Add support for auto-starting background services based on the running scope. Register services that start automatically in specific contexts - browser windows, web workers, desktop/server, or all of the above.

Getting Started

Add the NuGet package:

dotnet add package SpawnDev.BackgroundServices

Setup

using SpawnDev.BackgroundServices;

var builder = WebAssemblyHostBuilder.CreateDefault(args);

// Add the background service manager
builder.Services.AddBackgroundServiceManager();

// Register services that auto-start in ALL scopes
builder.Services.AddSingleton<IBackgroundService, MyService>();

// Register services that only auto-start in specific scopes
builder.Services.AddSingleton<IBackgroundService, MyWindowService>(GlobalScope.Window);
builder.Services.AddSingleton<IBackgroundService, MyWorkerService>(GlobalScope.AllWorkers);
builder.Services.AddSingleton<IBackgroundService, MyDesktopService>(GlobalScope.NonBrowser);

// Start all background services for the current scope
await builder.Build().Services.StartBackgroundServices();

Interfaces

IBackgroundService

Marker interface. Services implementing this are auto-started when StartBackgroundServices() is called, filtered by the registered GlobalScope.

public class MyService : IBackgroundService
{
    public MyService(ILogger<MyService> logger)
    {
        logger.LogInformation("MyService started");
    }
}

IAsyncBackgroundService

Extends IBackgroundService with a Task Ready property. The background service manager awaits Ready during startup, ensuring the service is fully initialized before other services that depend on it start.

public class MyAsyncService : IAsyncBackgroundService
{
    public Task Ready { get; }

    public MyAsyncService()
    {
        Ready = InitAsync();
    }

    private async Task InitAsync()
    {
        // async initialization
        await Task.Delay(100);
    }
}

IAsyncService

Interface with a Task Ready property. When resolved via GetServiceAsync<T>(), the container awaits Ready before returning the service.

GlobalScope

Flags enum controlling which scopes a service auto-starts in:

Value Description
Window Browser window
DedicatedWorker Dedicated web worker
SharedWorker Shared web worker
ServiceWorker Service worker
NonBrowser Desktop/server (.NET)
AllWorkers All worker types combined
AllBrowser Window + all workers
All Every scope
None Never auto-start

Targets

.NET 6.0, 7.0, 8.0, 9.0

License

MIT

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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on SpawnDev.BackgroundServices:

Package Downloads
SpawnDev.BlazorJS

Full Blazor WebAssembly and Javascript interop. Supports all Javascript data types and web browser APIs. Create, access properties, call methods, and add/remove event handlers of Javascript objects the .Net way without writing Javascript.

SpawnDev.SpawnJS

SpawnJS provides Javascript interop for .Net WebAssembly.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on SpawnDev.BackgroundServices:

Repository Stars
LostBeard/SpawnDev.BlazorJS
Full Blazor WebAssembly and Javascript interop. Supports all Javascript data types and web browser APIs.
Version Downloads Last Updated
2.0.0 0 8/1/2026
1.0.2 24,259 11/12/2025