Created
May 27, 2010 20:32
-
-
Save ryankelley/416300 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LogEntityCreation : Start should have a _bus.Subscribe(this) in it...
Otherwise the consumer is never subscribed.