Sample: Set Custom Migration Scoped Context
This example demonstrates how to set custom context in the migration scoped dependency injection container using an initialize migration hook. This is useful when other hooks like filters are registered with dependency injection and rely on migration scoped services.
Custom Context Service Class
public class CustomContext
{
public Guid CustomerId { get; set; }
}
Custom Context Service Class Dependency Injection
services.AddScoped<CustomContext>();
Initialize Migration Hook Class
from tableau_migration import(
InitializeMigrationHookBase,
IInitailizeMigrationHookResult
)
from Csharp.ExampleApplication.Hooks.InitializeMigration import CustomContext
class SetMigrationContextHook(InitializeMigrationHookBase):
def execute(self, ctx: IInitailizeMigrationHookResult) -> IInitailizeMigrationHookResult:
ctx.scoped_services._get_service(CustomContext)
Registration
plan_builder.hooks.add(SetMigrationContextHook)