1
votes

Thank you very much in advance.

My projects are targeting .NET Core 2.2.

I am trying to define a service that is using Masstransit 6.2.5, which uses SAGA Machine with a SQL database.

Using this code

services.AddMassTransit(cfg =>
              {
                  cfg.AddConsumersFromNamespaceContaining<SubmitVolunteerConsumer>(); //add consumer
                  cfg.AddSagaStateMachine<UserStateMachine, UserState>(typeof(UserStateMachineDefinition))

                  .EntityFrameworkRepository(r =>
                  {
                      r.ConcurrencyMode = ConcurrencyMode.Pessimistic;

                      services.AddDbContext<DbContext, UserStateDbContext>((provider, build) =>
                      {
                          build.UseSqlServer(connectionString, m =>
                          {
                              m.MigrationsAssembly(Assembly.GetExecutingAssembly().GetName().Name);
                              m.MigrationsHistoryTable($"__{nameof(UserStateDbContext)}");
                          });
                      });

                  });

                  cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, false));
              });

causes an issue because it requires MassTransit.EntityFrameworkCore 6.2.5 (however, this is using Microsoft.EntityFrameworkCore.Relational (3.1.3)) which is causing an error when I am trying to call/use the DBContext

Got this error

Could not load type 'Microsoft.EntityFrameworkCore.Infrastructure.IDbContextOptionsExtensionWithDebugInfo' from assembly 'Microsoft.EntityFrameworkCore, Version=3.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Could you please help me find a way to use SQL Server with my Saga machine without using a Nuget that references Entity Framework Core 3.x?

By the way, here is my Dbcontext

public UserStateDbContext(DbContextOptions options)
  : base(options)
{
}

protected override IEnumerable<ISagaClassMap> Configurations
{
    get { yield return new UserStateMap(); }
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    IConfigurationRoot configuration = new ConfigurationBuilder()
      .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
      .AddJsonFile("appsettings.json")
      .Build();
        optionsBuilder.UseSqlServer(configuration.GetConnectionString("GRPPortal"));

}
1
By the way, here is my Dbcontextsalma

1 Answers

3
votes

Why do you say "without using a Nuget that references Entity framework 3.x"? To use MassTransit 6.2.5 there is a dependency on EF Core 3.1.3+ for its EF Core persistence.

If you are using an older version of EF Core and cannot upgrade, then you need to look at an older version of MassTransit which still supports your EF Core version. This may require other binding re-directs for dependencies of MassTransit where there are newer versions in your project.

If you are using EF6 and don't want to add EFCore, then there is MassTransit.EntityFrameworkIntegration

If you are using a newer EF Core version, then this may be resolvable with a binding re-direct, however, given EF Core's rather volatile state, such as you're using EF Core 5.x, that may not be supported until a newer version of MassTransit is released.

If you just simply don't want to introduce any dependency on EF Core to have MassTransit work with SQL Server without EF then there are alternatives like using NHibernate. You can also consider writing your own persistence repository. I don't imagine it would be terribly difficult, given the source code for all of their official persistence is available here: https://github.com/MassTransit/MassTransit/tree/77eb5d724c8e33ebba6bb846b2a277e4d55fa65a/src/Persistence