question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Saga Persistence Configuration to AddMassTransit registration

See original GitHub issue

Create extension methods for the registration configurator (invoked via the .AddMassTransit container extension method) for the supported saga repositories so that they can easily be configured for the configured sagas (including state machine sagas).

This would configure the persistence components in the container so that they are properly resolved as the endpoints are configured. Should support an easy way to say “for all my sagas, use this” and let the registration sort it out (generics, vs explicit registrations, etc.).

Storage Engines

  • In Memory
  • NHiberate
  • Entity Framework
  • MongoDB
  • Redis
  • Marten
  • DocumentDb
  • Dapper
  • Azure Session State

Documentation

  • Consistent example stage machine and instance, following Automatonymous example
  • Top level introduction to the registration syntax

Bonus Features

  • Use a bus observer to connect/disconnect database connections for saga repositories when the bus is started/stopped, so that a failing connection might stop the bus from starting.

Repository Changes

Migrate the existing implementations to a new set of saga repository interfaces.

ISagaRepositoryContextFactory<TContext>

Used to created a SagaRepositoryContext<TContext> for each received message.

ISagaConsumeContextFactory<TContext, TSaga, TMessage>

Used to create a SagaConsumeContext<TSaga, TMessage> for a saga instance that has been loaded from storage or created by an initiating message.

ISagaRepository<TSaga>

Should remain mostly unchanged, but would have a standard implementation that uses the above interfaces to manage the repository interaction and focus purely on the saga behavior details (and dry up the saga repositories).

ILoadSagaRepository<T> and IQuerySagaRepository<T>

These are now consistent and supported by storage engines that have query and/or load support, and used by the unit testing extensions where available.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

3reactions
phatboygcommented, Dec 5, 2019

I think it will need to match whatever the built-in support is for the framework. If it’s EF, I think something like:

cfg.AddSaga<MySaga>()
    .EntityFrameworkRepository(ef =>
    {
        ef.DbContext<MySagaDbContext>(x => x.UseSqlServer(...))
    });

Basically give the same configuration extensions support that EF uses just start it with a different preample.

3reactions
NooNameRcommented, Dec 4, 2019

I’d like user to explicitly provide repo for a saga

cfg.AddSaga<Instance>()
    .UseEntityFrameworkRepository<YourDbContext>(repo => 
    {
         repo.ConcurrencyHandlingType = Pessimistic / Optimistic
    });

//or just provide connectionString
cfg.AddSaga<Instance>()
    .UseEntityFrameworkRepository(connectionString, repo => 
    {
         repo.ConcurrencyHandlingType = Pessimistic / Optimistic
    });

cfg.AddSaga<Instance>()
    .UseMongoDbRepository(connectionString, "database", repo => 
    {
         repo.CollectionName = "sagas";
    });
cfg.AddSaga<Instance>()
    .UseMongoDbRepository(IMongoDatabase, repo => 
    {
         repo.CollectionName = "sagas";
    });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Saga Persistence
When using the AddMassTransit container extension, the repository should be specified at saga registration. The example below specifies the InMemory saga ...
Read more >
Containers
The .AddMassTransit extension method, which is specific to each container, supports both registration and bus configuration. containerBuilder.
Read more >
Simplify setup for MassTransit Saga in Azure Service Bus
I'm trying to figure out how to set up a MassTransit saga and minimize the complexity of the setup in Azure Service Bus....
Read more >
MassTransit Season 2 - The Next Sample - YouTube
Season Two starts with a focused look at using MassTransit state machine sagas. In this first episode, the Library domain is explained, ...
Read more >
Sagas • NServiceBus - Particular Developer Portal
Instead, add an additional property that contains a unique saga instance identifier ... Make sure to configure appropriate saga persistence.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found