0

I have a list of products uniquely identified by name. each product has it's own ordering process. I'd like each products ordering process to be defined by a saga. is there a way for me to process each product using a different saga? Can i use endpoints for this? Would bus.Send(product name, message) work?

I hope this makes sense.

CurlyFro
  • 1,862
  • 4
  • 22
  • 39

2 Answers2

1

The short answer is no you can't call a saga by name. However, you can easily do this with standard messaging. You would just create a new more specific message which inherits from your product message base class. Then have your product specific saga be started by that message type.

Tyler Day
  • 1,690
  • 12
  • 12
  • gotcha but unfortunately i don't have concrete classes for my products. i have a base product class with dynamic properties and i have a string in the base class for the product name. my idea was, the end user would define their product then i could drop in the dll for the saga and presto everything would just work. any other ideas? – CurlyFro Mar 27 '15 at 17:54
  • Each specific saga you create, is going to require a specific message concrete class or interface to be defined, since sagas are not "called", they just handle message types in a pipeline. By design the message sender has no knowledge of who will handle the message. In your case, you can either do some switch statements based on the product name and send out the product specific message that way, which is ugly in my opinion. Or you can maybe store the message class name in your product database and instantiate via reflection like: – Tyler Day Mar 27 '15 at 19:30
  • System.Reflection.Assembly.GetExecutingAssembly().CreateInstance("messageClassName") – Tyler Day Mar 27 '15 at 19:30
  • One other option I just thought of, is to have an endpoint per product type. Then do bus.Send(productName + "Endpoint", productMessage); since you are allowed to route messages by name. If you have 100 product types, then this is not really viable. However if you have 5-10, then maybe it's worth a look. – Tyler Day Mar 27 '15 at 19:54
  • cool -- that's what i thought but needed to make sure. why would you think 100 product types/endpoints is not good? – CurlyFro Mar 27 '15 at 19:57
  • Mostly from a maintenance standpoint it might be a bit much. Up to you though. – Tyler Day Mar 27 '15 at 20:00
1

You can do some custom saga finding logic (as described here) to control this. For a more complete example, check out this blog post which shows how to do that based on headers.

Udi Dahan
  • 11,932
  • 1
  • 27
  • 35