---
title: "Instance class"
canonical: https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/Instance
---

# Instance class

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

```csharp
public static class Instance
```

## Public Members

| name                                                                                                            | description                                                                                                                                                                        |
| --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| static [HasStarted](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/Instance/HasStarted) { get; } | Whether this instance has finished starting: true once every [`Starting`](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/Instance/Starting) callback has completed. |
| static event [Starting](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/Instance/Starting)        | Raised 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`](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/Instance/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`](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/InstanceStartAttribute) instead. For state that every instance can share, use [`Template`](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk/Isoplane/Template). [The application lifecycle](https://isoplane.dev/docs/concepts/application-lifecycle) explains templates and instances in full.

## Examples

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

```csharp
var instance = Guid.Empty;

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

## See Also

- namespace [Isoplane](https://isoplane.dev/docs/reference/sdk/Isoplane.Sdk)
