NServiceBus
NServiceBus copied to clipboard
Consider dropping support for sending/publishing interfaces
This issue was transferred from a private repository
The send/publish API allows to do something like:
context.Send<IAmAnInterface>( e => { /* set interface properties */ } );
context.Publish<IAmAnInterface>( e => { /* set interface properties */ } );
At the sender/publisher what happens is that a class is dynamically generated and used when such an invocation happens. There are 2 reasons that come to my mind to use interfaces to define messages:
- versioning
- immutability
Versioning is mostly if not only a receiver concern, not a sender one, in which case the receiver is interested in dealing with interfaces not necessarily senders.
Immutability is even nicer, IMO, it would allow to define something like:
interface ISomethingHappened
{
string Something{ get; }
}
receivers should not be allowed to change anything on the received message. However if we need to use that interface at send/publish time it must have a public setter as well, otherwise this doesn't compile:
context.Publish<ISomethingHappened>( e => e.Something = "reason" );
this means that the sender/publisher needs to define a class, that implements ISomethingHappened, in any case. Which makes nearly useless the ability to directly send or publish interfaces.
It seems that the only good reason to allow sending/publishing interfaces is to reduce the amount of required code (resharper can easily do things like this). The proposal is to drop support for it, and force users to define classes that implement the interfaces they want to publish/send.