Hi,
Here is code :
In my first plugin :
public int Subscribehoroscope(SubscribeHoroscopeModel subscribeHoroscope)
{
try
{
Horoscopes.Domain.SubscribeHoroscope horo = (from h in _subscribesRepository.Table
where h.Email == subscribeHoroscope.Email
select h).FirstOrDefault();
if (horo == null)
{
Guid guid = Guid.NewGuid();
horo = new SubscribeHoroscope();
horo.Active = subscribeHoroscope.Active;
horo.CreatedOnUtc = subscribeHoroscope.CreatedOnUtc;
horo.SunSignId = subscribeHoroscope.SunSignId;
horo.Email = subscribeHoroscope.Email;
horo.HoroscopeSubscriptionGuid = guid;
horo.Name = subscribeHoroscope.Name;
horo.StoreId = subscribeHoroscope.StoreId;
horo.CustomerId = subscribeHoroscope.CustomerId;
horo.IsSent = false;
_subscribesRepository.Insert(horo);
//event notification
_eventPublisher.EntityInserted(horo);
return horo.Id;
}
else
{
return -1;
}
}
catch (Exception ex)
{
throw ex;
}
}
And in my second plugin :
public class MailChimpECommerceEventConsumer : IConsumer<EntityInserted<SubscribeHoroscope>>,
IConsumer<EntityUpdated<SubscribeHoroscope>>
{
/// <summary>
/// Handles the event.
/// </summary>
/// <param name="insertedOrder">Inserted order</param>
public void HandleEvent(EntityInserted<SubscribeHoroscope> inserted)
{
if (PluginIsActive)
{
_synchronizationRecordService.CreateOrUpdateRecord(EntityType.HoroscopeSubscription, inserted.Entity.Id, ActionType.Create, inserted.Entity.Email);
}
}
/// <summary>
/// Handles the event.
/// </summary>
/// <param name="insertedOrder">Inserted order</param>
public void HandleEvent(EntityUpdated<SubscribeHoroscope> updated)
{
if (PluginIsActive)
{
_synchronizationRecordService.CreateOrUpdateRecord(EntityType.HoroscopeSubscription, updated.Entity.Id, ActionType.Update, updated.Entity.Email);
}
}
}
I'm not able to identify what I'm missing. When event publish from first plugin, scope returns empty array.
/// <summary>
/// Publish event
/// </summary>
/// <typeparam name="T">Type</typeparam>
/// <param name="eventMessage">Event message</param>
public virtual void Publish<T>(T eventMessage)
{
var subscriptions = _subscriptionService.GetSubscriptions<T>();
subscriptions.ToList().ForEach(x => PublishToConsumer(x, eventMessage));
}