Skip to main content

Configuration and hosting

Framework-neutral SynapsysWorker​

Direct use requires only the core namespace. The worker owns a client it creates, but never disposes a caller-supplied HttpClient or ILoggerFactory.

using Basamento.Synapsys;
using Microsoft.Extensions.Logging;

var options = new SynapsysOptions
{
CoreUrl = new Uri("https://core.example.com"),
CoreToken = Environment.GetEnvironmentVariable("SYNAPSYS_CORE_TOKEN"),
WorkerName = "catalog-worker",
};

using var loggerFactory = LoggerFactory.Create(logging => logging.AddConsole());
using var httpClient = new HttpClient();
await using var worker = new SynapsysWorker(options, loggerFactory, httpClient);

// Register processes here.
await worker.StartAsync();
await applicationStopping;
await worker.StopAsync();

No ASP.NET Core, Generic Host, or DI container is required. StartAsync validates, performs the health probe, and starts heartbeats. StopAsync is idempotent and non-throwing for process, transport, and shutdown failures. A stopped worker cannot be restarted.

Options​

new SynapsysOptions() first reads canonical environment variables; explicit property assignments override those values.

PropertyEnvironment variableDefault
EnabledSYNAPSYS_ENABLEDtrue
CoreUrlSYNAPSYS_CORE_URLrequired when enabled
CoreTokenSYNAPSYS_CORE_TOKENnone; missing token warns
WorkerNameSYNAPSYS_WORKER_NAMEentry assembly name
HostSYNAPSYS_HOSTmachine hostname
HeartbeatIntervalSYNAPSYS_HEARTBEAT_INTERVAL5s; positive whole seconds
FailFastSYNAPSYS_FAIL_FASTfalse
ConnectTimeoutSYNAPSYS_CONNECT_TIMEOUT2s
RequestTimeoutSYNAPSYS_REQUEST_TIMEOUT5s
ShutdownTimeoutSYNAPSYS_SHUTDOWN_TIMEOUT10s
CaptureConsoleSYNAPSYS_CAPTURE_CONSOLEtrue

Environment durations require a unit. Enabled = false is a complete runtime no-op. Unknown keys are rejected by the hosting configuration binder.

Generic Host and dependency injection​

Import Basamento.Synapsys.Extensions.Hosting and register one configuration section or an Action<SynapsysOptions>:

using Basamento.Synapsys.Extensions.Hosting;

var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddScoped<BusinessProcesses>();

builder.Services
.AddSynapsys(builder.Configuration.GetSection("Synapsys"))
.AddEndless<BusinessProcesses>(
"event-consumer",
static (service, token) => service.ConsumeEventsAsync(token))
.AddProgressive<BusinessProcesses>(
"catalog-import",
static service => service.ImportCatalogAsync());

await builder.Build().RunAsync();

Each accepted run creates a fresh async DI scope. The requested service follows its registered lifetime; scoped and transient dependencies are disposed when the method returns. The worker, registration descriptors, hosted service, HTTP integration, and process log provider are singleton infrastructure.

The hosting package uses IHttpClientFactory; it does not create a second manually owned pool. Its IHostedService starts and stops the worker with the host's CancellationToken, so application shutdown is graceful and shares the configured hard deadline. Standard Synapsys__CoreUrl environment mapping applies to a host configuration section and overrides the canonical defaults.

Next: register realistic business methods and logs.