Class ServiceProxyContext
- Namespace
- Nerdbank.JsonRpc.BrokeredServices
- Assembly
- Nerdbank.JsonRpc.dll
Supplies a leased service target and local invocation boundary policy.
public abstract class ServiceProxyContext : IDisposable, IAsyncDisposable
- Inheritance
-
ServiceProxyContext
- Implements
- Inherited Members
Properties
EventTarget
Gets the current target for event attachment.
protected abstract object? EventTarget { get; }
Property Value
IsDisposed
Gets a value indicating whether the proxy is disposed.
public abstract bool IsDisposed { get; }
Property Value
Logger
Gets the logger used to observe notification and cleanup failures.
public ILogger<ServiceProxyContext> Logger { get; init; }
Property Value
RpcOptions
Gets the exception disclosure policy for direct calls.
public JsonRpcOptions RpcOptions { get; init; }
Property Value
Remarks
Local failures retain their original inner exception when details are enabled; no typed exception payload is serialized or reconstructed.
Methods
Borrow(object, ILogger<ServiceProxyContext>?, JsonRpcOptions?)
Creates a callback boundary without taking ownership of the caller's target.
public static ServiceProxyContext Borrow(object target, ILogger<ServiceProxyContext>? logger = null, JsonRpcOptions? rpcOptions = null)
Parameters
targetobjectThe caller-owned callback target.
loggerILogger<ServiceProxyContext>The callback logger.
rpcOptionsJsonRpcOptionsThe exception disclosure policy.
Returns
- ServiceProxyContext
The disposable boundary. Disposing it does not dispose the supplied target.
DetachEvents()
Detaches all event subscriptions before releasing a target.
protected void DetachEvents()
Dispose()
Disposes this context and relinquishes its owning reference.
public abstract void Dispose()
DisposeAsync()
Disposes this context and awaits owned resource cleanup.
public abstract ValueTask DisposeAsync()
Returns
- ValueTask
A task tracking cleanup.
IsInterfaceEnabled(Type)
Tests whether a generated optional interface is currently available.
public virtual bool IsInterfaceEnabled(Type interfaceType)
Parameters
interfaceTypeTypeThe optional interface.
Returns
- bool
Whether the context currently supports it.
MoveEvents(object?)
Moves event attachments to a replacement generation.
protected void MoveEvents(object? target)
Parameters
targetobjectThe replacement target, or null while unavailable.
ObserveNotification(ValueTask)
Observes a generated fire-and-forget invocation.
public void ObserveNotification(ValueTask operation)
Parameters
operationValueTaskThe invocation to observe.
Own(object, IDisposable?, bool, ILogger<ServiceProxyContext>?, JsonRpcOptions?)
Owns a local target for a newly acquired proxy.
public static ServiceProxyContext Own(object target, IDisposable? owner = null, bool translateExceptions = true, ILogger<ServiceProxyContext>? logger = null, JsonRpcOptions? rpcOptions = null)
Parameters
targetobjectThe local service object.
ownerIDisposableThe object to dispose instead of the target, if supplied.
translateExceptionsboolWhether service exceptions cross a local RPC boundary.
loggerILogger<ServiceProxyContext>The direct-call logger.
rpcOptionsJsonRpcOptionsThe exception disclosure policy.
Returns
- ServiceProxyContext
The context, which owns the target until disposed.
RejectArgumentOnlyResult<T>(T?, ServiceProxyLease)
Enforces the request-argument-only rule for call-scoped contracts and progress receivers on direct calls.
public T? RejectArgumentOnlyResult<T>(T? target, ServiceProxyLease lease) where T : class
Parameters
targetTThe returned value.
leaseServiceProxyLeaseThe active invocation.
Returns
- T
Null when the result is null; non-null call-scoped results always fail.
Type Parameters
TThe call-scoped contract.
RentAsync(CancellationToken)
Acquires a target for the duration of an invocation.
public abstract ValueTask<ServiceProxyLease> RentAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenCancels acquisition.
Returns
- ValueTask<ServiceProxyLease>
A lease that must be disposed exactly once.
ReportCallbackException(Exception)
Observes a callback failure without throwing into service code.
public void ReportCallbackException(Exception exception)
Parameters
exceptionExceptionThe callback failure.
Retain(IDuplexPipe?, ServiceProxyLease)
Retains a generation until both returned pipe ends are completed.
public IDuplexPipe? Retain(IDuplexPipe? pipe, ServiceProxyLease lease)
Parameters
pipeIDuplexPipeThe returned pipe.
leaseServiceProxyLeaseThe active invocation.
Returns
- IDuplexPipe
The caller-owned pipe boundary.
Retain(PipeReader?, ServiceProxyLease)
Retains a generation until a returned reader is completed.
public PipeReader? Retain(PipeReader? reader, ServiceProxyLease lease)
Parameters
readerPipeReaderThe returned reader.
leaseServiceProxyLeaseThe active invocation.
Returns
- PipeReader
The caller-owned reader boundary.
Retain(PipeWriter?, ServiceProxyLease)
Retains a generation until a returned writer is completed.
public PipeWriter? Retain(PipeWriter? writer, ServiceProxyLease lease)
Parameters
writerPipeWriterThe returned writer.
leaseServiceProxyLeaseThe active invocation.
Returns
- PipeWriter
The caller-owned writer boundary.
Retain(Stream?, ServiceProxyLease)
Retains a generation until a returned stream is disposed.
public Stream? Retain(Stream? stream, ServiceProxyLease lease)
Parameters
streamStreamThe returned stream.
leaseServiceProxyLeaseThe active invocation.
Returns
- Stream
The caller-owned stream boundary.
RetainProxy<T>(T?, ServiceProxyLease)
Creates a generated direct proxy for a returned marshalable object.
public T? RetainProxy<T>(T? target, ServiceProxyLease lease) where T : class
Parameters
targetTThe returned object.
leaseServiceProxyLeaseThe active invocation.
Returns
- T
A caller-owned object boundary retaining its parent generation.
Type Parameters
TThe returned source-generated contract.
RetainSubscription(IDisposable?, ServiceProxyLease, Func<object, CancellationToken, ValueTask<IDisposable?>>?)
Retains a service generation while a returned subscription is active.
public virtual IDisposable? RetainSubscription(IDisposable? subscription, ServiceProxyLease lease, Func<object, CancellationToken, ValueTask<IDisposable?>>? resubscribe = null)
Parameters
subscriptionIDisposableThe service's subscription.
leaseServiceProxyLeaseThe active invocation lease.
resubscribeFunc<object, CancellationToken, ValueTask<IDisposable>>The generated operation for restoring observer subscriptions after replacement.
Returns
- IDisposable
A subscription that releases its generation exactly once.
Retain<T>(IObserver<T>?, ServiceProxyLease)
Retains a generation for a returned observer without taking ownership of its target.
public IObserver<T>? Retain<T>(IObserver<T>? observer, ServiceProxyLease lease)
Parameters
observerIObserver<T>The returned observer.
leaseServiceProxyLeaseThe active invocation.
Returns
- IObserver<T>
The observer boundary, or the caller's original observer when round-tripping.
Type Parameters
TThe observed value.
TranslateException(Exception)
Translates a local target exception without serializing arguments or results.
public virtual Exception TranslateException(Exception exception)
Parameters
exceptionExceptionThe target failure.
Returns
- Exception
The exception to report to the caller.
UpdateEvent<THandler>(string, THandler?, Action<object, THandler>, Action<object, THandler>, bool, Func<THandler, THandler>?)
Updates an event attachment owned by this proxy.
public void UpdateEvent<THandler>(string key, THandler? handler, Action<object, THandler> attach, Action<object, THandler> detach, bool add, Func<THandler, THandler>? wrap = null) where THandler : Delegate
Parameters
keystringThe generated event identity.
handlerTHandlerThe client handler.
attachAction<object, THandler>The generated typed add operation.
detachAction<object, THandler>The generated typed remove operation.
addboolWhether to add rather than remove.
wrapFunc<THandler, THandler>The generated callback boundary, if needed.
Type Parameters
THandlerThe event delegate.
WrapProxy<T>(T?)
Creates a borrowed generated callback boundary, preserving round trips of service-owned objects.
public T? WrapProxy<T>(T? target) where T : class
Parameters
targetTThe caller-owned target.
Returns
- T
The borrowed proxy, or the original service object when returning across its own boundary.
Type Parameters
TThe source-generated callback interface.
WrapProxy<T>(T?, out IDisposable?)
Creates a callback boundary whose lifetime can be limited to one invocation.
public T? WrapProxy<T>(T? target, out IDisposable? boundary) where T : class
Parameters
targetTThe caller-owned target.
boundaryIDisposableThe boundary to dispose when the call or returned enumeration ends; never the caller's target.
Returns
- T
The generated callback proxy.
Type Parameters
TThe source-generated callback interface.
Wrap<T>(IObserver<T>?)
Isolates observer callbacks from local service code without serialization.
public IObserver<T>? Wrap<T>(IObserver<T>? observer)
Parameters
observerIObserver<T>The caller's observer.
Returns
- IObserver<T>
A direct callback boundary.
Type Parameters
TThe observed value.
Wrap<T>(IObserver<T>?, out IDisposable?)
Creates an observer callback boundary that can be revoked if activation or invocation fails.
public IObserver<T>? Wrap<T>(IObserver<T>? observer, out IDisposable? boundary)
Parameters
observerIObserver<T>The caller's observer.
boundaryIDisposableThe borrowed boundary, never the caller's observer.
Returns
- IObserver<T>
The service's observer argument.
Type Parameters
TThe observed value.
Wrap<T>(IProgress<T>?)
Isolates progress callbacks from local service code without serialization.
public IProgress<T>? Wrap<T>(IProgress<T>? progress)
Parameters
progressIProgress<T>The caller's progress receiver.
Returns
- IProgress<T>
A direct callback boundary.
Type Parameters
TThe progress value.
Wrap<T>(IProgress<T>?, out IDisposable?)
Creates a progress callback boundary that lasts for one invocation or enumeration.
public IProgress<T>? Wrap<T>(IProgress<T>? progress, out IDisposable? boundary)
Parameters
progressIProgress<T>The caller's receiver.
boundaryIDisposableThe boundary to dispose when the invocation ends.
Returns
- IProgress<T>
The service's progress argument.
Type Parameters
TThe progress value.