vs-streamjsonrpc icon indicating copy to clipboard operation
vs-streamjsonrpc copied to clipboard

Feature request: option\setting to prevent\disallow duplicate methods in targets

Open osexpert opened this issue 4 years ago • 6 comments

When adding multiple rpc target classes, if multiple targets contain the same\similar method, the method in first target added is used (as documented). But I miss an option to disallow duplicates, as this is (in my case) always an error. Alternatives: -Preferably a setting on JsonRpc itself that produce error when AddLocalRpcTarget is called -A setting on JsonRpc itself that produce error during runtime, when duplicate method is attempted called -A setting in JsonRpcTargetOptions, that produce error when AddLocalRpcTarget is called -A setting in JsonRpcTargetOptions, that produce error during runtime, when duplicate method is attempted called

Thanks.

osexpert avatar Sep 10 '20 14:09 osexpert

Thanks for the feedback.

A setting in JsonRpcTargetOptions, that produce error when AddLocalRpcTarget is called

I think this is a reasonable design.

AArnott avatar Sep 10 '20 14:09 AArnott

Another thing that could solve the problem for me was if I could create multiple proxies and specify proxy option to alter method name (via delegate), eg. proxy for Service1 would postfix methods with Service1_ etc. Target already has option for method name modification so AddLocalRpcTarget(new Service1(), options) would already expose methods prefixed Service1_

osexpert avatar Sep 12 '20 20:09 osexpert

Interesting. @gdalsnes are you aware that JsonRpcProxyOptions also offers you a method name transform delegate? So you can add the service prefix both on the target and proxy sides already.

https://github.com/microsoft/vs-streamjsonrpc/blob/d945aa899db79544faa7b92caa4564b81d6400cc/src/StreamJsonRpc/JsonRpcProxyOptions.cs#L53

AArnott avatar Sep 13 '20 03:09 AArnott

Interesting. @gdalsnes are you aware that JsonRpcProxyOptions also offers you a method name transform delegate? So you can add the service prefix both on the target and proxy sides already.

Ok great, I will try that!

osexpert avatar Sep 13 '20 08:09 osexpert

It works but it actually got a lot more complicated with dozens of proxies instead of one super-proxy IServer (IServer : IService1, IService2, etc.) that I use via generic wrapper, the wrapper has a reference to the super-proxy, when recreating super-proxy after recreating JsonRpc (when the stream dies etc.) this just works. So for me I think the duplicate check is still helpful. Sorry.

osexpert avatar Sep 14 '20 19:09 osexpert

Interesting conversation. We used the method and event name transforms to solve this problem. But, in our case, every target has a unique identifier, so it was easy to transform the name to <ID>:<Interface>.<MethodName>. Also works because information on every target is published as part of our discovery system, so we are able to hide this complexity from someone using the system.

rruizGit avatar Oct 12 '20 16:10 rruizGit