Console / Worker Service (C#)
Run the ISA SDK in a .NET console app or hosted Background Service: DI, hosted services, and graceful cancellation.
Console / Worker Service (C#)
Integrate the ISA SDK into a .NET 8 console app or a BackgroundService worker. Both use the same DI setup — the difference is whether a host runs.
Prerequisites
- .NET 8+
dotnet add package IsaSdkISA_TOKENin your environment orappsettings.json
Plain console (no host)
For scripts, one-off jobs, and lightweight tools:
using Isa.Sdk;
using Isa.Sdk.Catalog;
using Isa.Sdk.Zyins;
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
var ct = cts.Token;
// Reads ISA_TOKEN from the environment.
var isa = IsaClient.WithBearer();
var result = await isa.Zyins.Prequalify.RunAsync(new PrequalifyRequest(
Applicant: new Applicant
{
Dob = "1962-04-18",
Sex = Sex.Male,
HeightInches = 70,
WeightPounds = 195,
State = "NC",
NicotineUse = new NicotineUsageInput { LastUsed = NicotineDuration.Never },
},
Coverage: Coverage.ByFaceValue(25_000),
Products: new[] { Products.Fex.AetnaAccendo }), ct);
foreach (var offer in result.Plans)
{
var headline = offer.Pricing.FirstOrDefault(r => r.Primary);
Console.WriteLine(
$"{offer.Carrier.Name} {offer.Product.Name} " +
$"{headline?.Eligibility.Category} {headline?.Premium?.Amount.Display}");
}Isa is thread-safe, so reuse the same instance in batch jobs:
var tasks = applicants.Select(a => isa.Zyins.Prequalify.RunAsync(BuildInput(a), ct));
var results = await Task.WhenAll(tasks);Hosted Worker Service
For long-running background processors (SQS consumer, scheduled jobs):
// Program.cs
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Isa.Sdk;
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddSingleton(_ => IsaClient.WithBearer());
services.AddHostedService<PrequalifyWorker>();
})
.Build();
await host.RunAsync();// PrequalifyWorker.cs
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Isa.Sdk;
using Isa.Sdk.Zyins;
public sealed class PrequalifyWorker(Isa isa, ILogger<PrequalifyWorker> logger) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
try
{
await ProcessNextAsync(stoppingToken);
}
catch (OperationCanceledException)
{
// Graceful shutdown — do not log as error.
break;
}
catch (IsaRateLimitException ex)
{
var delay = ex.RetryAfter ?? TimeSpan.FromSeconds(1);
logger.LogWarning("rate limited — backing off {Delay}", delay);
await Task.Delay(delay, stoppingToken);
}
catch (IsaException ex)
{
logger.LogError("isa error: code={Code} requestId={RequestId}", ex.CodeEnum, ex.RequestId);
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
}
}
private async Task ProcessNextAsync(CancellationToken ct)
{
// Dequeue applicant, build input, call isa.Zyins.Prequalify.RunAsync
await Task.CompletedTask;
}
}Error handling
| Exception | Cause | Action |
|---|---|---|
IsaConfigException | ISA_TOKEN missing at startup | Set the env var; fix before deploying |
IsaValidationException | Malformed input | Log ex.Param; fix the pipeline |
IsaRateLimitException | 429 | Task.Delay(ex.RetryAfter) |
IsaIdempotencyConflictException | Key reused with different body | Log and discard; mint a new key |
IsaException | Any other 4xx/5xx | Log ex.RequestId; retry on 5xx |
Configuration
| Setting | Source |
|---|---|
ISA_TOKEN | Environment variable or secrets manager reference |
ISA_BASE_URL | Override for staging; omit in production |
Do not store ISA_TOKEN in appsettings.json checked into source control. For local dev, use dotnet user-secrets. In production, use your secrets provider (e.g., Azure Key Vault, AWS Secrets Manager).
See also
Updated about 10 hours ago