Open lillo42 opened 2 years ago
Hi @lillo42, I'm not sure I understand the question.
Sagas are invoked using a dependency injection container. Is that what you're referring to? Then any parameter in the constructor of the saga should theoretically also be injected by the DI container, if it is properly regsitered.
This code throw null reference, if I comment the Console.WriteLine("{0}", _depedency.IsEnable);
on ConfigureHowToFindSaga
works:
public class SampleSaga : Saga<SampleData>, IAmStartedByMessages<SomeMessage>
{
private readonly SomeDependency _depedency;
public SampleSaga(SomeDependency depedency)
{
_depedency = depedency;
}
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<SampleData> mapper)
{
Console.WriteLine("{0}", _depedency.IsEnable);
mapper.ConfigureMapping<SomeMessage>(x => x.Id)
.ToSaga(x => x.Id);
}
public async Task Handle(SomeMessage message, IMessageHandlerContext context)
{
Console.WriteLine("{0}", _depedency.IsEnable);
}
}
I understand now what you're looking for. The ConfigureHowToFindSaga
is intended to only configure the mappings. It should not be used for anything else. If you're doing conditional mapping, the saga is probably already getting too complex.
Is there a specific scenario you want to achieve that I might be able to help with?
@dvdstelt I'm trying to integrate/playing with Automatonymous lib with NServiceBus, for that I'm using source code generator to generate the saga, so for ConfigureHowToFindSaga I want to use NServiceStateMachine instance(which one is singleton) to configure how to find saga.
A sample of a state machine https://github.com/lillo42/NServiceBus.Automatonymous/blob/code-improve/sample/SimpleStateMachine/OrderStateMachine.cs
Automatonymous seems to be a state machine, something a saga could be seen as, as well. It feels like you're overcomplicating things by combining those two, or I am lacking to fail what you're trying to achieve.
If you want a more complex way to find a specific saga, you can use the IFindSagas interface. I'm still failing to see what you're trying to achieve. If you're generating source code, can't you generate the mapping? I can investigate what you're trying to achieve with Automatonymous, but that would take me a while and I'm still not sure that would help me understand what you're trying to achieve?
Hi,
I'm testing source code generation with NServiceBus, so I have a constructor where I receive some parameter that I want to use
ConfigureHowToFindSaga
but those parameter is null, apparently whenConfigureHowToFindSaga
the constructor isn't been call, is that correct?