Skip to content

Startup Services

Startup services run immediately after the dependency injection container is built. They support full constructor injection like any other service, which makes them the perfect place to hook global application events — wiring up a logout handler, warming a cache, subscribing to a message bus, or scheduling jobs.

IShinyStartupTask.Start() is intentionally synchronous. The platform does not wait for your app startup to finish, so any async work you kick off here runs in a fire-and-forget fashion. If you block for too long, the OS can kill your app before it finishes launching.

using Shiny;
namespace MyApp.Infrastructure;
public class MyStartupService : IShinyStartupTask
{
readonly ILogger<MyStartupService> logger;
public MyStartupService(ILogger<MyStartupService> logger)
{
this.logger = logger;
}
public void Start()
{
// Hook global events, warm caches, etc.
this.logger.LogInformation("App started");
}
}
using Shiny;
// wherever you register your services with the service collection
builder.Services.AddShinyService<MyStartupService>(); // registers as a singleton
// Start() runs automatically when the service provider is built / Shiny host runs

AddShinyService<T>() registers the implementation for every interface it implements (including IShinyStartupTask) and wires it into the startup pipeline. You do not need a separate AddSingleton<IShinyStartupTask, MyStartupService>() call.