# IMigrationApplier

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.imigrationapplier/
> Summary: IMigrationApplier: Applies the pending migrations of the active SQL persistence provider.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

Applies the pending migrations of the active SQL persistence provider.

```csharp
public interface IMigrationApplier
```

## Remarks

Each `Use*` extension (`UsePostgreSql`, `UseSqlServer`, and
`UseSqlite`) registers this interface with `Replace`, resolving to
the provider's migration runner - the same instance
[ISqlPersistenceDiagnostics](/api/tracon.isqlpersistencediagnostics/) resolves to.

This is the public way to apply migrations from your own code, for example
from a deployment step when `AutoApplyMigrations` is off. The runner
itself is not public: each SQL provider package compiles its own copy, and
this interface, which lives in `Tracon.Abstractions`, is the one type
all three share. `IServiceProvider.GetRequiredService<IMigrationApplier>`
therefore resolves without knowing which provider is active, even in an
application that references more than one of them.

**DI lifetime — singleton.** Registered as a singleton with
`Replace` by whichever SQL provider is active.

Call this interface; the SQL provider package supplies the implementation, so do not
implement or replace it.

## Methods

### <a id="Tracon_IMigrationApplier_ApplyAsync_System_Threading_CancellationToken_"></a> ApplyAsync\(CancellationToken\)

Applies every pending migration, in order.

```csharp
ValueTask<int> ApplyAsync(CancellationToken cancellationToken = default)
```

#### Parameters

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[int](https://learn.microsoft.com/dotnet/api/system.int32)\>

The number of migrations applied.
