Table of Contents

Class Interaction<TInput, TOutput>

Namespace
ReactiveUI
Assembly
ReactiveUI.dll

Represents an interaction between collaborating application components.

public class Interaction<TInput, TOutput> : Object, IInteraction<TInput, TOutput>

Type Parameters

TInput

The interaction's input type.

TOutput

The interaction's output type.

Inheritance
Interaction<TInput, TOutput>
Implements
IInteraction<TInput, TOutput>
Extension Methods
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)

Remarks

Interactions allow collaborating components in an application to ask each other questions. Typically, interactions allow a view model to get the user's confirmation from the view before proceeding with some operation. The view provides the interaction's confirmation interface in a handler registered for the interaction.

Interactions have both an input and an output. Interaction inputs and outputs use generic type parameters. The interaction's input provides handlers the information they require to ask a question. The handler then provides the interaction with an output as the answer to the question.

By default, handlers are invoked in reverse order of registration. That is, handlers registered later are given the opportunity to handle interactions before handlers that were registered earlier. This chaining mechanism enables handlers to be registered temporarily in a specific context, such that interactions can be handled differently according to the situation. This behavior can be modified by overriding the Handle(TInput) method in a subclass.

Note that handlers are not required to handle an interaction. They can choose to ignore it, leaving it for some other handler to handle. The interaction's Handle(TInput) method will throw an UnhandledInteractionException<TInput, TOutput> if no handler handles the interaction.

Constructors

Interaction(IScheduler?)

Represents an interaction between collaborating application components.

public Interaction(IScheduler? handlerScheduler = null)

Parameters

handlerScheduler IScheduler

The scheduler to use when invoking handlers, which defaults to CurrentThreadScheduler.Instance if null.

Remarks

Interactions allow collaborating components in an application to ask each other questions. Typically, interactions allow a view model to get the user's confirmation from the view before proceeding with some operation. The view provides the interaction's confirmation interface in a handler registered for the interaction.

Interactions have both an input and an output. Interaction inputs and outputs use generic type parameters. The interaction's input provides handlers the information they require to ask a question. The handler then provides the interaction with an output as the answer to the question.

By default, handlers are invoked in reverse order of registration. That is, handlers registered later are given the opportunity to handle interactions before handlers that were registered earlier. This chaining mechanism enables handlers to be registered temporarily in a specific context, such that interactions can be handled differently according to the situation. This behavior can be modified by overriding the Handle(TInput) method in a subclass.

Note that handlers are not required to handle an interaction. They can choose to ignore it, leaving it for some other handler to handle. The interaction's Handle(TInput) method will throw an UnhandledInteractionException<TInput, TOutput> if no handler handles the interaction.

Methods

GenerateContext(TInput)

Gets a interaction context which is used to provide information about the interaction.

protected virtual IOutputContext<TInput, TOutput> GenerateContext(TInput input)

Parameters

input TInput

The input that is being passed in.

Returns

IOutputContext<TInput, TOutput>

The interaction context.

GetHandlers()

Gets all registered handlers by order of registration.

protected Func<IInteractionContext<TInput, TOutput>, IObservable<Unit>>[] GetHandlers()

Returns

Func<IInteractionContext<TInput, TOutput>, IObservable<Unit>>[]

All registered handlers.

Handle(TInput)

Handles an interaction and asynchronously returns the result.

public virtual IObservable<TOutput> Handle(TInput input)

Parameters

input TInput

The input for the interaction.

Returns

IObservable<TOutput>

An observable that ticks when the interaction completes.

Remarks

This method passes the interaction in turn to its registered handlers in reverse order of registration until one of them handles the interaction. If the interaction remains unhandled after all its registered handlers have executed, an UnhandledInteractionException<TInput, TOutput> is thrown.

RegisterHandler(Action<IInteractionContext<TInput, TOutput>>)

Registers a synchronous interaction handler.

public IDisposable RegisterHandler(Action<IInteractionContext<TInput, TOutput>> handler)

Parameters

handler Action<IInteractionContext<TInput, TOutput>>

The handler.

Returns

IDisposable

A disposable which, when disposed, will unregister the handler.

Remarks

This overload of RegisterHandler is only useful if the handler can handle the interaction immediately. That is, it does not need to wait for the user or some other collaborating component.

RegisterHandler(Func<IInteractionContext<TInput, TOutput>, Task>)

Registers a task-based asynchronous interaction handler.

public IDisposable RegisterHandler(Func<IInteractionContext<TInput, TOutput>, Task> handler)

Parameters

handler Func<IInteractionContext<TInput, TOutput>, Task>

The handler.

Returns

IDisposable

A disposable which, when disposed, will unregister the handler.

Remarks

This overload of RegisterHandler is useful if the handler needs to perform some asynchronous operation, such as displaying a dialog and waiting for the user's response.

RegisterHandler<TDontCare>(Func<IInteractionContext<TInput, TOutput>, IObservable<TDontCare>>)

Registers an observable-based asynchronous interaction handler.

public IDisposable RegisterHandler<TDontCare>(Func<IInteractionContext<TInput, TOutput>, IObservable<TDontCare>> handler)

Parameters

handler Func<IInteractionContext<TInput, TOutput>, IObservable<TDontCare>>

The handler.

Returns

IDisposable

A disposable which, when disposed, will unregister the handler.

Type Parameters

TDontCare

The signal type.

Remarks

This overload of RegisterHandler is useful if the handler needs to perform some asynchronous operation, such as displaying a dialog and waiting for the user's response.