title: MassTransit help registering multiple sagas
body: <p>I'm working on porting an old app to .net6, and ran into an issue with registrering multiple sagas with masstransit.</p>
  <pre><code>services.AddMassTransit&lt;IProcessManagerBus&gt;(busCfg =&gt;
  {
      busCfg.AddSagaStateMachine&lt;OrderPM, OrderPMState&gt;()
          .EntityFrameworkRepository&lt;OrderPMState&gt;(efConfig =&gt;
          {
              efConfig.ConcurrencyMode = ConcurrencyMode.Optimistic;
              efConfig.DatabaseFactory(() =&gt; new OrderStateDbContext(configuration.GetConnectionString(&quot;DB&quot;)));
          });
      
      busCfg.AddSagaStateMachine&lt;CsaLoginPM, CsaLoginPMState&gt;()
          .EntityFrameworkRepository&lt;CsaLoginPMState&gt;(efConfig =&gt;
          {
              efConfig.ConcurrencyMode = ConcurrencyMode.Optimistic;
              efConfig.DatabaseFactory(() =&gt; new CsaLoginStateDbContext(configuration.GetConnectionString(&quot;DB&quot;)));
          });
      
      busCfg.UsingRabbitMq((context, rabbitCfg) =&gt;
      {
          rabbitCfg.UseJsonSerializer();
          rabbitCfg.Host(new Uri(configuration.GetValue&lt;string&gt;(&quot;messaging:pm-bus:host-address&quot;)), hostCfg =&gt;
          {
              hostCfg.Username(configuration.GetValue&lt;string&gt;(&quot;messaging:pm-bus:username&quot;));
              hostCfg.Password(configuration.GetValue&lt;string&gt;(&quot;messaging:pm-bus:password&quot;));        
              
              rabbitCfg.ReceiveEndpoint(configuration.GetValue&lt;string&gt;(&quot;messaging:pm-bus:receive-queue&quot;), epCfg =&gt;
              {
                  epCfg.PrefetchCount = 10;
                  epCfg.UseRetry(retryConfig =&gt; retryConfig.Exponential(5, TimeSpan.FromMilliseconds(500), TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(1)));
                  
                  epCfg.ConfigureSagas(context);
              });
          });
      });
  });
  </code></pre>
  <p>The OrderPMState works fine, but the CsaLoginPMState gives the following error when triggered: <strong>System.InvalidOperationException: The entity type CsaLoginPMState is not part of the model for the current context.</strong></p>
  <p>If I comment out the registration of the OrderPMState, the CsaLoginPMState works fine. I suspect, that the 2 sagas are using the same DbContext, despite being registered with their individual DbContext.</p>
  <p><strong>OrderStateDbContext</strong></p>
  <pre><code>public class OrderStateDbContext : SagaDbContext
  {
      public OrderStateDbContext(string nameOrConnectionString)
          : base(nameOrConnectionString)
      {
      }
  
      protected override IEnumerable&lt;ISagaClassMap&gt; Configurations
      {
          get { yield return new OrderPMStateMapping(); }
      }
  }
  </code></pre>
  <p><strong>CsaLoginStateDbContext</strong></p>
  <pre><code>public class CsaLoginStateDbContext : SagaDbContext
  {
      public CsaLoginStateDbContext(string nameOrConnectionString)
          : base(nameOrConnectionString)
      {
      }
  
      protected override IEnumerable&lt;ISagaClassMap&gt; Configurations
      {
          get { yield return new CsaLoginPMStateMapping(); }
      }
  }
  </code></pre>
  <p>The old version of the app used AutoFac, and the registration was done like this:</p>
  <pre><code>builder.Register(x =&gt;
      EntityFrameworkSagaRepository&lt;OrderPMState&gt;.CreateOptimistic(() =&gt; new OrderStateDbContext(_configuration.GetConnectionString(&quot;DB&quot;))))
      .As&lt;ISagaRepository&lt;OrderPMState&gt;&gt;().SingleInstance();
  
  builder.Register(x =&gt;
      EntityFrameworkSagaRepository&lt;CsaLoginPMState&gt;.CreateOptimistic(() =&gt; new CsaLoginStateDbContext(_configuration.GetConnectionString(&quot;DB&quot;))))
      .As&lt;ISagaRepository&lt;CsaLoginPMState&gt;&gt;().SingleInstance();
  </code></pre>
  <p>Am I missing something?</p>