Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to handle anything dynamically #24

Closed
mookid8000 opened this issue Jan 10, 2012 · 4 comments
Closed

Add ability to handle anything dynamically #24

mookid8000 opened this issue Jan 10, 2012 · 4 comments

Comments

@mookid8000
Copy link
Member

by implementing IHandleMessages<dynamic>. That would be cool!

(not sure how an IHandleMessages<dynamic> would actually behave at the moment... is it just a question of having the Dispatcher resolve those as well?

ssboisen added a commit to ssboisen/Rebus that referenced this issue Feb 26, 2012
@ssboisen
Copy link
Contributor

Exactly what kind of behavior are you looking for here? You can't implement a dynamic interface but if you implement IHandleMessages < object > and change the object to dynamic in the Handle-method you basicly have dynamic message handling. The dispatcher will dispatch any message to the handler (if you change the implementation of IActivateHandlers and IDetermineDestination aswell) since anything is object and the Handler having dynamic in the method-signatur will allow you to call anything (at compiletime) on that object.

I modified the sample project to show off this already supported feature using ExpandoObject. Anonymous object weren't posible since the json serializer threw up when it tried to deserialize the transportmessage in the worker however with a working serializer it won't be a problem, the message gets serialized and is put in the server-queue, the server just can't desirialize the anonymous object.

@ssboisen
Copy link
Contributor

Hmm, maybe exposing an abstract class DynamicMessageHandler : IHandleMessage < object > which already have the Handle(object message) changed to Handle(dynamic message) would be an idea, this way whoever wanted to have dynamic message handling wouldn't have to know this small workaround - if you can call it that - they just need to inherit from DynamicMessageHandler. Obviously that could be a problem for anyone needing to inherit from another baseclass aswell but it would be a nice "api-workaround" for those who don't.

@mookid8000
Copy link
Member Author

Yeah, well - I'm actually unsure as to whether IHandleMessages<dynamic> makes any sense after all... what kind of usage scenario could we come up with?

@mookid8000
Copy link
Member Author

Even though this scenario may seem kind of whack, I think it is already supported. C# doesn't allow a class to implement IHandleMessages<dynamic> though, but you can implement IHandleMessages<object> and then provide a method with a Handle(dynamic message) signature as the implementation.

Just remember that the message type must be public for this to work ;) as the runtime binder seems to respect access modifiers.

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

No branches or pull requests

2 participants