Skip to content

Instantly share code, notes, and snippets.

@ryankelley
Created May 27, 2010 20:32
Show Gist options
  • Save ryankelley/416300 to your computer and use it in GitHub Desktop.
Save ryankelley/416300 to your computer and use it in GitHub Desktop.
public interface IMessage{}
[Serializable]
public class Created<T> :IMessage
{
public Guid Id { get; set; }
public T Entity { get; set; }
public Created(T entity):this()
{
Entity = entity;
}
public Created()
{
Id = Guid.NewGuid();
}
public Created(Guid id, T entity):this(entity)
{
Id = id;
}
}
public void PublishMessage()
{
var service = new Service("Test", 123M, "EA", "1235");
var message = new Created<Service>(service);
ObjectFactory.GetInstance<IEventAggregator>().SendMessage(message);
}
public class LogEntityCreation : Consumes<Created<Service>>.All, IBusService
{
private IServiceBus _bus;
public void Consume(Created<Service> message)
{
Console.WriteLine(string.Format("Entity: {0} was created on {1}", message.Entity.GetType(), message.Entity.Created));
}
public void Dispose()
{
_bus.Dispose();
}
public void Start(IServiceBus bus)
{
_bus = bus;
}
public void Stop()
{
throw new NotImplementedException();
}
}
@phatboyg
Copy link

LogEntityCreation : Start should have a _bus.Subscribe(this) in it...

Otherwise the consumer is never subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment