Path: redb/redb.Templates/templates/redb-worker/RedbWorker.Module/InitRoute.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Templates/templates/redb-worker/RedbWorker.Module/InitRoute.cs ---- using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using redb.Core; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.File; using RedbWorker.Module.Models; using RedbWorker.Module.Routes; namespace RedbWorker.Module; /// /// The module's entry point. A Tsak worker finds it by convention (a public static class /// InitRoute with a main(IRouteContext) method) and awaits it when the module loads; /// RedbWorker.Host calls the same method, so the route code exists once. /// Order: settings, components, the database, then the routes. /// public static class InitRoute { public static async Task main(IRouteContext context) { var settings = ModuleSettings.FromContext(context); settings.EnsureFolders(); var logger = context.GetService()?.CreateLogger("RedbWorker"); var services = context.GetServiceProvider() ?? throw new InvalidOperationException("The route context has no service provider; redb is not available."); if (!context.HasComponent("file")) context.AddComponent(new FileComponent()); // The module's schemes, through a scope of its own: the connection goes back to the pool as soon // as this is done. Every ProcessWithRedb step gets its own IRedbService the same way: the host's // default redb, registered in its DI container. Under Tsak that is Tsak:Redb:Provider. await using (var scope = services.CreateAsyncScope()) { var redb = scope.ServiceProvider.GetRequiredService(); await redb.SyncSchemeAsync(); } var routes = (RouteContext)context; routes.AddRoutes(new ExceptionRouteBuilder()); routes.AddRoutes(new OrderInboxRouteBuilder()); logger?.LogInformation("RedbWorker module ready: inbox {Inbox}, receipts to {Outbox}", settings.Inbox, settings.Outbox); return context; } }