Skip to content

Migration guide 1.1.x to 2.0.x

vsljivic edited this page Nov 8, 2023 · 16 revisions

This release contains several breaking changes. Most notably:

  • Upgrading MediatR to version 12
  • Publishing domain events via ISaveChangesInterceptor (Enigmatry.Entry.EntityFramework building block)
  • Removing the IDbContextAccessTokenProvider (Enigmatry.Entry.EntityFramework building block)

Upgrading MediatR to version 12

We updated building blocks to target MediatR v12. With this version of MediatR a lot of breaking changes were introduced. Please follow the upgrade guide when updating your project.

Publishing domain events via ISaveChangesInterceptor

We introduced PublishDomainEventsInterceptor for publishing domain events. This means MediatRDbContext base class is removed. Update your project's DbContext to inherit from BaseDbContext instead:

- public class BlueprintContext : MediatRDbContext
+ public class BlueprintContext : BaseDbContext
{
-    public BlueprintContext(DbContextOptions options,
-        IMediator mediator,
-        IDbContextAccessTokenProvider dbContextAccessTokenProvider,
-        ILogger<BlueprintContext> logger) :
-        base(CreateOptions(), options, mediator, logger, dbContextAccessTokenProvider)
+    public BlueprintContext(DbContextOptions options) :
+        base(CreateOptions(), options)
    {
    }
}

PublishDomainEventsInterceptor needs to be registered with DI and EntityFramework otherwise domain events will not be published. This is a major changes since previously nothing additionally needed to be done except for inheriting from the `MediatRDbContext'.

Registering PublishDomainEventsInterceptor:

// Registering interceptors as self because we want to resolve them individually to add them to the DbContextOptions in the correct order
+ builder.RegisterType<PublishDomainEventsInterceptor>().AsSelf().InstancePerLifetimeScope();

// Interceptors can be registered with EF via DbContextOptions
private DbContextOptions CreateDbContextOptions(IComponentContext container)
{
	var optionsBuilder = new DbContextOptionsBuilder();
...
+	// Interceptors will be executed in the order they are added
+	optionsBuilder.AddInterceptors(container.Resolve<PublishDomainEventsInterceptor>());

	return optionsBuilder.Options;
}

Removing the IDbContextAccessTokenProvider

This provider was needed to negotiate connection with Azure SQL Database when application is using managed identity to access. With new versions of the Microsoft.Data.SqlClient negotiation and acquiring of an access token is done in by the library it self.

IDbContextAccessTokenProvider is not needed and can be removed:

- builder.RegisterType<DbContextAccessTokenProvider>().As<IDbContextAccessTokenProvider>().InstancePerLifetimeScope();

Database connection string for your test / acc / prod environment needs to be updated to include Authentication=Active Directory Default;:

- Server=tcp:enigmatry-test.database.windows.net,1433;Database=enigmatry-blueprint-test;Connection Timeout=30
+ Server=tcp:enigmatry-test.database.windows.net,1433;Database=enigmatry-blueprint-test;Authentication=Active Directory Default;Connection Timeout=30

Blueprint Template PR

For more details, you can check the PR for upgrading packages in the Blueprint Template.