/// <summary> /// Registers a content handler for a particular type of payload. /// </summary> /// <typeparam name="TPayload">The specific type of payload for this handler.</typeparam> /// <typeparam name="T1">The type of the first parameter.</typeparam> /// <typeparam name="T2">The type of the second parameter.</typeparam> /// <param name="contentFactory">The content factory with which to register the handler.</param> /// <param name="handle">The function with which to handle the payload.</param> /// <param name="handlerClass">The class of handler (e.g. "viewFactory", "messageDispatcher").</param> /// <returns>The content factory.</returns> public static ContentFactory RegisterContentEnvelopeHandler <TPayload, T1, T2>(this ContentFactory contentFactory, Action <TPayload, T1, T2> handle, string handlerClass) { if (contentFactory is null) { throw new ArgumentNullException(nameof(contentFactory)); } if (handle is null) { throw new ArgumentNullException(nameof(handle)); } if (handlerClass is null) { throw new ArgumentNullException(nameof(handlerClass)); } string contentType = ContentFactory.GetContentType <TPayload>(); contentFactory.RegisterContentHandler <ContentEnvelope, T1, T2>( contentType, (envelope, param1, param2) => handle(envelope.GetContents <TPayload>(), param1, param2), handlerClass); return(contentFactory); }
/// <summary> /// Registers a content handler for a particular type of payload. /// </summary> /// <typeparam name="TPayload">The specific type of payload for this handler.</typeparam> /// <typeparam name="THandler">The type of the handler.</typeparam> /// <typeparam name="T1">The type of the first parameter.</typeparam> /// <typeparam name="T2">The type of the second parameter.</typeparam> /// <typeparam name="T3">The type of the third parameter.</typeparam> /// <param name="contentFactory">The content factory with which to register the handler.</param> /// <param name="handlerClass">The class of handler (e.g. "viewFactory", "messageDispatcher").</param> /// <param name="handlerFactory">A factory function to create the singleton handler.</param> /// <returns>The content factory.</returns> public static ContentFactory RegisterContentEnvelopeHandler <TPayload, THandler, T1, T2, T3>(this ContentFactory contentFactory, string handlerClass, Func <IServiceProvider, THandler> handlerFactory) where THandler : class, IContentHandler <TPayload, T1, T2, T3> { if (contentFactory is null) { throw new ArgumentNullException(nameof(contentFactory)); } if (handlerClass is null) { throw new ArgumentNullException(nameof(handlerClass)); } if (handlerFactory is null) { throw new ArgumentNullException(nameof(handlerFactory)); } string contentType = ContentFactory.GetContentType <TPayload>(); contentFactory.Services.AddSingleton(handlerFactory); contentFactory.RegisterContentHandler <ContentEnvelope, ContentEnvelopeHandlerWithClass <TPayload, THandler, T1, T2, T3>, T1, T2, T3>(contentType, handlerClass); return(contentFactory); }