c# - Castle interface proxy with a dynamic target -
i trying use castle dynamicproxy implement typesafe version of signalr hub. goal being when use clients.all rather getting dynamic object have interface use.
the code rather hacky @ moment wanted prove work before go through trouble of making nice:
public interface ichatclient { void broadcastmessage(string name, string message); } public class chathub : typesafehub<ichatclient> { public void send(string name, string message) { clients.all.broadcastmessage(name, message); } } public abstract class typesafehub<tinterface> : hub tinterface:class { public new typesafehubcallerconnectioncontext<tinterface> clients { { return new typesafehubcallerconnectioncontext<tinterface>(base.clients); } } } public class typesafehubcallerconnectioncontext<t> t:class { private ihubcallerconnectioncontext context; private proxygenerator proxygen; public typesafehubcallerconnectioncontext(ihubcallerconnectioncontext context) { this.context = context; proxygen= new proxygenerator(); } public t { { return proxygen.createinterfaceproxywithtarget<t>(context.all); }
right when i'm returning proxy fails because target not implement interface.
is there easy way achieve goal or should @ using interfaceproxywithouttarget , using interceptor wire call dynamic.
you seem on right track.
this feature slated release in signalr 2.1. can @ how implemented here: https://github.com/signalr/signalr/commit/3c4b8794b0f512daec677110a8e41ac717514584
while there way castle dynamicproxy, might simpler use impromptuinterface.
every call made typedclientbuilder<t>.build(_dynamiccontext...)
replaced impromptu.actlike<t>(_dynamiccontext...)
. in case, call impromptu.actlike
replace proxygen.createinterfaceproxywithtarget
.
if feel adventurous, can try out signalr nightlies myget have feature included.
Comments
Post a Comment