M.Ang wrote:Well, the HandleEvent method is called on the Consumer in EvnentHandler#PublishToConsumer
private static void PublishToConsumer<T>(IConsumer<T> x, T eventMessage)
{
try
{
x.HandleEvent(eventMessage);
}
And this happens when the Publish() method is called (with the relevant Event type)
public void Publish<T>(T eventMessage)
{
var subscriptions = _subscriptionService.GetSubscriptions<T>();
subscriptions.ToList().ForEach(x => PublishToConsumer(x, eventMessage));
}
The subscriptionService uses reflection to gather all the IConsumer types with the template parameter equal to the event type.
So if your plugin implement IConsumer<OrderPlacedEvent>, when that event is fired (on the PlaceOrder method of the OrderProcessingService) YourPlugin.HandleEvent() should be called, asking for an instance shouldn't trigger the event.
You can try this yourself by breaking on the Publish method when you place an order, and see how the IConsumers defined on the SMS plugins gets loaded and called.
Check that the Plugin is actually being loaded though!
Hope i didn't misunderstood your issue here, anyway if you want you can provide code to aid debugging.
Thanks for getting back to me. Here is my HandleEvent Method
public void HandleEvent(OrderPlacedEvent eventMessage)
{
//is plugin installed?
var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName("Misc.FavoriteCategories");
if (pluginDescriptor == null)
return;
var plugin = pluginDescriptor.Instance() as FavoriteCategoriesPlugin;
if (plugin == null)
return;
var order = eventMessage.Order;
if (plugin.AddFavoriteCategories(order.Id))
{
order.OrderNotes.Add(new OrderNote()
{
Note = "Categories Added to favorites if valid",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow
});
_orderService.UpdateOrder(order);
}
}
The code never gets passed this line
var plugin = pluginDescriptor.Instance() as FavoriteCategoriesPlugin;
When debugging you go down a huge hierarchy of methods before returning to the web browser and the order is placed without executing ever executing this
plugin.AddFavoriteCategories(order.Id)