1

I am able to register a MassTranst SagaStateMachine in a SimpleInjector container using the InMemoryRepository:

container.AddMassTransit(cfg =>
{
    // Unrelated registration code ommitted
    // ...

    cfg.AddSagaStateMachine<FormEvaluateStateMachine, FormEvaluateState>()
        .InMemoryRepository();
});

container being the SimpleInjector container.

If I change the line in there to:

cfg.AddSagaStateMachine<FormEvaluateStateMachine, FormEvaluateState>() .RedisRepository();

I get the following error from simple injector:

For the container to be able to create RedisSagaRepositoryContextFactory it should have only one public constructor: it has 2. See https://simpleinjector.org/one-constructor for more information.

So somewhere its trying to register an implementation for RedisSagaRepositoryContextFactory which indeed has two constructors.

Is there an elegant way to solve this? It looks like SimpleInjector offers a kludge to allow for multiple constructors but enabling that anti-pattern on a systemwide basis seems a little heavyhanded.

Is there a way to tell SimpleInjector to only do it for certain types? I assume I want to use the constructor that takes ConnectionMultiplexer but I'm not certain. I would have tagged my post with SimpleInjector but I don't have enough internet points.

Maybe there is a better way to specify the RedisRepository() so this doesn't happen?

I'm also in full framework so maybe not having Redis itself properly registered is my issue?

2
  • Seems like a bug in the MassTransit integration package.
    – Steven
    Sep 11, 2021 at 17:39
  • Otherwise, try overriding the registration for RedisSagaRepositoryContextFactory with a custom one that use a delegate.
    – Steven
    Sep 11, 2021 at 17:41

1 Answer 1

1

It should be using the ConnectionMultiplexer constructor, seems like an issue with Simple Injector not being able to figure it out.

Seems like you can specify a strategy for constructor selection, and override the default behavior only for that type.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.