Skip to content

Instantly share code, notes, and snippets.

@mskutta
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mskutta/7db4b97b9a740212cfe5 to your computer and use it in GitHub Desktop.
Save mskutta/7db4b97b9a740212cfe5 to your computer and use it in GitHub Desktop.
EvaluateResult Service Bus Code
// Convert item to model object / entity / dto
var entity = _mapper.Map(item); // This is dependent on the mapper you decide to use.
if (entity == null)
return;
var entityType = entity.GetType();
// Create the message we want to send on the service bus
var operation = (context.Action == PublishAction.DeleteTargetItem && !context.PublishOptions.CompareRevisions) ? PublishOperation.Deleted : context.Result.Operation;
if (operation == PublishOperation.Created)
messageType = typeof(CreatedEvent<>).MakeGenericType(entityType);
if (operation == PublishOperation.Updated)
messageType = typeof(UpdatedEvent<>).MakeGenericType(entityType);
if (operation == PublishOperation.Deleted)
messageType = typeof(DeletedEvent<>).MakeGenericType(entityType);
if (messageType == null)
return;
// Add the entity to the message
var publishEvent = Activator.CreateInstance(messageType);
((IEvent)publishEvent).Id = context.ItemId.Guid;
var property = messageType.GetProperty("Entity");
if (property != null)
property.SetValue(publishEvent, entity, null);
// Publish the event on the service bus
_bus.Publish(publishEvent); // This is dependent on the service bus you decide to use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment