WampSharp icon indicating copy to clipboard operation
WampSharp copied to clipboard

client proxy + subscriber combo

Open BrannonKing opened this issue 8 years ago • 4 comments

I would like an interface that combines events and methods like this:

public interface IAssetManager {
   public void Add(AssetDto asset); // WampMethod
   public event Action<AssetDto> AssetAdded; // WampEvent
}

Then, after I create the client proxy, I want to add a subscription for the event:

var proxy = channel.RealmProxy.Services.GetCalleeProxy<IAssetManager>();
channel.RealmProxy.Services.RegisterSubscriber(proxy);

Essentially, the AssetAdded on the client proxy should subscribe to the topic when I subscribe (at least once) to the event on the interface. Is there some way I can add another Castle Proxy interceptor to make that happen? Or can I use an abstract callee where I define the event add/remove to do my own subscription? Is there some other approach recommended?

BrannonKing avatar Nov 04 '15 17:11 BrannonKing

I guess you want something like this:

var proxy = 
    channel.RealmProxy.Services.GetPublisherProxy<IAssetPublisher>();

proxy.AssetAdded += MyEvent;

(There is no need to call a subscribe method, this will happen implicitly when the first event is added).

For symmetry one might consider the GetSubscriberProxy overload:

var proxy = 
    channel.RealmProxy.Services.GetSubscriberProxy<IAssetSubscriber>();

Task<long?> publicationId = await proxy.RaiseAssetAdded(new AssetDto() {});

And one might also consider the combo overload:

var proxy = 
    channel.RealmProxy.Services.GetServiceProxy<IAssetService>();

proxy.AssetAdded += MyEvent;

proxy.Add(new AssetDto());

Task<long?> publicationId = await proxy.RaiseAssetAdded(new AssetDto() {});

This can all of course be implemented as mechanisms similar to the current reflection-based caller implementation, but will require a lot of work. This also has issues with .NET variants, since Castle isn't available yet for PCL (nor for .NET Core) and therefore we'll need different implementations there. I'm not sure I want to get in to this journey right now. I think we already have a nice reflection-based subscriber implementation, and if that is not enough, one can always implement manually a custom subscriber library using the raw subscriber api (see meta-api implementation).

I might implement this in a future version, but for now I recommend you to wrap the RegisterSubscriber/Raw Subscriber variants in your own code (you might even use Castle yourself in order to write these wrapped stuff automatically).

darkl avatar Nov 04 '15 19:11 darkl

I played around with this a little more today. Apparently I can't put an event on an interface that I intend to use for RPC proxy? It expects a procedure for every member of the interface. Is there some way to mark interface members as "ignore"?

BrannonKing avatar Nov 17 '15 21:11 BrannonKing

Yeah, you should not put events in the proxy interfaces - the library doesn't know how to handle them. What kind of "Ignore" behavior do you expect to happen? I mean, when you subscribe to that kind of event what should happen?

darkl avatar Nov 17 '15 21:11 darkl

To get the appropriate "ignore" behavior, add this to the WampCalleeProxyFactory.GetProxy: .Where(m => !m.IsSpecialName). That should make it skip events and properties and prevent us from adding interceptors for them. In addition, you could add some kind of predicate method to ICalleeProxyInterceptor to allow us to skip methods.

BrannonKing avatar Nov 22 '16 17:11 BrannonKing