public async Task <ISagaInstance> Activate <TEvent>(IReceiveEvent <TEvent> receiver, TEvent @event, CancellationToken cancellationToken) where TEvent : class, IEvent { Contract.Requires(receiver != null); Contract.Requires(@event != null); Contract.Ensures(Contract.Result <Task <ISagaInstance> >() != null); var sagaType = receiver.GetType(); var metadata = sagaMetadata.Find(sagaType); var activator = activators.GetOrAdd(metadata.SagaDataType, CreateActivator); var instance = activator.Activate(receiver, metadata, clock); var searchResult = await activator.GetData(instance, storage, @event, cancellationToken).ConfigureAwait(false); await AttachData(instance, searchResult, @event, cancellationToken).ConfigureAwait(false); return(instance); }
/// <summary> /// Returns a value indicating whether the event receiver is a saga. /// </summary> /// <typeparam name="TEvent">The type of event.</typeparam> /// <param name="eventReceiver">The <see cref="IReceiveEvent{T}">event receiver</see> to evaluate.</param> /// <returns>True if the <paramref name="eventReceiver">event receiver</paramref> is a saga; otherwise, false.</returns> public static bool IsSaga <TEvent>(this IReceiveEvent <TEvent> eventReceiver) where TEvent : IEvent { Arg.NotNull(eventReceiver, nameof(eventReceiver)); return(eventReceiver.GetType().IsSaga()); }