Question

I am using Raven to persist sagas and I want to implement IFindSagas, I need to find the saga based on 2 properties, SiteId & EmailAddress so ConfigureMapping won't work. The ISagaPersister interface only lets you look up a single saga by a single property.

I have implemented a saga finder like this

public class MySagaFinder : IFindSagas<MySagaData>.Using<ISomeMessage>
{
    public ISagaPersister Persister { get; set; }

    public MySagaData FindBy(ISomeMessage message)
    {
        var lookup = string.Format("{0}__{1}", message.SiteId, message.EmailAddress);
        return Persister.Get<MySagaData>("SagaLookup", lookup);
    }
}

So basically I've added a property on MySagaData called SagaLookup which is a concatenation of SiteId and EmailAddress. I can then look it up by this. This feels like a hack. Is there any way using the saga persister that I can either get a saga back by multiple properties or get a list of sagas back based on one property that I can then filter by the other property?

Was it helpful?

Solution

IMO it is best to look up by a single "key" property because then you don't need to implement a custom persister. Concatenating the site ID and email address may seem like a hack, but if you think of that as defining the ID of that specific saga then it makes sense. The saga data isn't part of your domain model, it is part of the infrastructure which has specific requirements. However, you should consider whether this definition of the saga ID is unique enough. For example, would it ever be possible for two saga's for the same user in the same site ID to execute at the same time?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top