/// <summary> /// Adds a responder to the service collection. This method registers the responder as being available for all /// <see cref="IResponder{T}"/> implementations it supports. /// </summary> /// <param name="serviceCollection">The service collection.</param> /// <param name="responderType">The type implementing <see cref="IResponder"/>.</param> /// <param name="group">The group the responder belongs to.</param> /// <returns>The service collection, with the responder added.</returns> /// <exception cref="ArgumentException">Throws if responderType does not implement <see cref="IResponder"/>.</exception> public static IServiceCollection AddResponder ( this IServiceCollection serviceCollection, Type responderType, ResponderGroup group = ResponderGroup.Normal ) { if (!responderType.IsResponder()) { throw new ArgumentException( $"{nameof(responderType)} should implement {nameof(IResponder)}.", nameof(responderType)); } var responderTypeInterfaces = responderType.GetInterfaces(); var responderInterfaces = responderTypeInterfaces.Where ( r => r.IsGenericType && r.GetGenericTypeDefinition() == typeof(IResponder <>) ); foreach (var responderInterface in responderInterfaces) { serviceCollection.AddScoped(responderInterface, responderType); } serviceCollection.AddScoped(responderType); serviceCollection.Configure <ResponderService> ( responderService => responderService.RegisterResponderType(responderType, group) ); return(serviceCollection); }
/// <summary> /// Adds a responder to the service collection. This method registers the responder as being available for all /// <see cref="IResponder{T}"/> implementations it supports. /// </summary> /// <param name="serviceCollection">The service collection.</param> /// <param name="group">The group the responder belongs to.</param> /// <typeparam name="TResponder">The concrete responder type.</typeparam> /// <returns>The service collection, with the responder added.</returns> public static IServiceCollection AddResponder <TResponder> ( this IServiceCollection serviceCollection, ResponderGroup group = ResponderGroup.Normal ) where TResponder : IResponder { return(serviceCollection.AddResponder(typeof(TResponder), group)); }