# IPlugin interface

> The entry point of a Plugin's C# half: the one public class in its code DLL that the engine creates and hands a PluginContext.

Namespace `EvilEngine.Api`, assembly `EvilEngine.Api`. Engine commit 4ff877b1.

```csharp
public interface IPlugin
```

The entry point of a Plugin's C# half: the one public class in its `code` DLL that the engine creates and hands a [PluginContext](/docs/api/plugincontext).

The host has a loader for it. It opens the DLL named by `code` in `plugin.toml` in its own collectible load context, looks for exactly one public, non-abstract type that implements `IPlugin`, and creates it with its parameterless constructor. Zero or two such types is an error naming them. The boot reads each Plugin's manifest and resolves the load order, and each session's server realm loads the code of every resolved Plugin whose `side` is `both` or `server` as it starts, in that order, and unloads it as it ends. A Plugin whose code doesn't load, or whose `Load` throws, is left out of that session with a note naming it, and what it registered goes with it.

```csharp
public sealed class Fungus : IPlugin
{
    public void Load(PluginContext context)
    {
    }

    public void Unload()
    {
    }
}
```

## Members

### Load (method)

```csharp
void Load(PluginContext context)
```

Called once per realm the Plugin runs in, with that realm's [PluginContext](/docs/api/plugincontext). Everything the Plugin does goes through the context, which is how the engine knows which Plugin made what. Keep the context if you need it later; there are no statics to reach the engine.

The server realm calls it as a session starts. The client realm doesn't load Plugin code yet.

### Unload (method)

```csharp
void Unload()
```

Called before the Plugin's load context is let go. It's for anything outside the engine the Plugin opened itself, like a file handle or a thread. Drop every reference into the engine here, or the collectible context can't be collected.

Called as the session ends, in the reverse of the load order. Whatever the Plugin registered goes after it returns, even if it throws.
