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

Make support for marshaled objects available for custom types #774

Closed
matteo-prosperi opened this issue Mar 3, 2022 · 1 comment · Fixed by #777
Closed

Make support for marshaled objects available for custom types #774

matteo-prosperi opened this issue Mar 3, 2022 · 1 comment · Fixed by #777
Milestone

Comments

@matteo-prosperi
Copy link
Member

Could you please consider making marshaled object support available for custom interfaces?

The goal would be to allow an RPC interface to expose APIs like

public interface IMyServer
{
  Task<IFoo> GetSomethingAsync();
  Task GiveSomethingAsync(IBar bar);
}

The caller would call await GetSomethingAsync() and receive a disposable proxy of an IFoo object.
The caller would call await GiveSomethingAsync(bar) and the server would receive a disposable proxy for the bar object.

Calls to methods exposed by the IFoo and IBar proxies would result in RPC calls and the corresponding method being executed on the corresponding object.

The receiver of a marshaled object will be responsible for disposing of the proxy. I am not sure if it should be mandatory for interfaces that are marshaled as objects to be IDisposable (i.e., interface IFoo : IDisposable and interface IBar : IDisposable).

This feature request doesn't cover any other members other than methods (e.g. properties), I don't have a use case for that.

Thanks

@AArnott
Copy link
Member

AArnott commented Mar 3, 2022

The place to start investigation of this feature is probably here:

(typeof(IDisposable), new JsonRpcProxyOptions { MethodNameTransform = CommonMethodNameTransforms.CamelCase }, new JsonRpcTargetOptions { MethodNameTransform = CommonMethodNameTransforms.CamelCase }),

This line (and the surrounding array) is what controls which types will get marshaled instead of serialized.

At the moment this is a static list. I believe the static list should remain, but any use of that list may be augmented with another list that is maintained on a per-JsonRpc instance basis, or perhaps by checking for an attribute on the interface being tested.

I think we should start with requiring any additional interfaces to derive from IDisposable, since that makes it more obvious to the receiver that they should dispose of these proxies. If we need to we can always remove that requirement, but adding it later would be a breaking change, so I prefer to start conservatively.

@AArnott AArnott changed the title [Feature request] Make support for marshaled objects available for custom types Make support for marshaled objects available for custom types Mar 3, 2022
@AArnott AArnott linked a pull request Mar 18, 2022 that will close this issue
@AArnott AArnott added this to the v2.11 milestone Mar 18, 2022
matteo-prosperi added a commit that referenced this issue Mar 18, 2022
This PR addresses #774.

Added the `RpcMarshalable` attribute that can be applied to an interface that:
- extends IDisposable,
- doesn't have properties,
- doesn't have events.

See https://github.com/microsoft/vs-streamjsonrpc/blob/main/doc/rpc_marshalable_objects.md for more information.

Co-authored-by: Matteo Prosperi <maprospe@microsoft.com>
Co-authored-by: Andrew Arnott <andrewarnott@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants