microsoft / vs-streamjsonrpc

The StreamJsonRpc library offers JSON-RPC 2.0 over any .NET Stream, WebSocket, or Pipe. With bonus support for request cancellation, client proxy generation, and more.
Other
741 stars 149 forks source link

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

Open osexpert opened 4 years ago

osexpert commented 4 years ago

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.

AArnott commented 4 years ago

Thanks for the feedback.

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

I think this is a reasonable design.

osexpert commented 4 years ago

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

AArnott commented 4 years ago

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

osexpert commented 4 years ago

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 commented 4 years ago

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.

rruizGit commented 4 years ago

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 :.. 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.