Skip to main content

Instance class

Lets an application set up state that must differ between instances, as each instance starts.

public static class Instance

Public Members​

namedescription
static HasStarted { get; }Whether this instance has finished starting: true once every Starting callback has completed.
static event StartingRaised once in each instance, before the instance handles its first request.

Remarks​

Isoplane initializes the application ahead of requests and saves its memory as a template. It then scales copies of the application with traffic, up to the application’s instance limit. Each copy is an instance and starts from the template. Whatever existed when the template was saved is therefore identical in every instance, including a random value drawn at start-up. Subscribe to Starting to replace such state when an instance starts.

Isoplane already reseeds, before the event is raised, every Random created without a seed, Random.Shared, the generator behind Activity trace and span identifiers, and the one behind SQLite's random() and randomblob(). Each cryptographic randomness call draws fresh bytes. Your application reseeds generators it seeded explicitly and generators that libraries implement themselves. It also replaces values already drawn, such as an identifier stored in a static field. Use the same hook to refresh shared state that may have changed since preparation, such as protection keys and their revocations.

An application written without ASP.NET has no start-up code to subscribe from, and marks one method with InstanceStartAttribute instead. For state that every instance can share, use Template. The application lifecycle explains templates and instances in full.

Examples​

In Program.cs, before await app.RunAsync():

var instance = Guid.Empty;

Instance.Starting += () =>
{
instance = Guid.NewGuid();
return Task.CompletedTask;
};

See Also​