ApplicationContext: Passing parameters to Migrations

kalenwatermeyer edited this page Mar 2, 2016 · 6 revisions
Clone this wiki locally

ApplicationContext is an object passed in by the Migration Runner that is available to migrations to be used as a switch.

To set the ApplicationContext when running migrate.exe

Run migrate.exe ... --context MyArgument. This will set the application context to the string "MyArgument".

To set the ApplicationContext when running migration in code

Set runner.ApplicationContext to an arbitrary C# object, such as a string: runner.ApplicationContext = "MyArgument"; or when creating the RunnerContext:

var migrationContext = new FluentMigrator.Runner.Initialization.RunnerContext(announcer)
    ApplicationContext = clientName

To use the ApplicationContext

Inside your migration, you can access the context via this.ApplicationContext. So for instance:

if ((string)this.ApplicationContext == "MyArgument")