///
/// Adds the given game event responder.
///
/// The service collection.
/// The type of the event responder.
/// The collection.
public static IServiceCollection AddGameResponder(this IServiceCollection serviceCollection, Type gameResponder)
{
if (!gameResponder.GetInterfaces().Any(
i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IGameResponder<>)
))
{
throw new ArgumentException(
$"{nameof(gameResponder)} should implement IGameResponder.",
nameof(gameResponder));
}
var handlerTypeInterfaces = gameResponder.GetInterfaces();
var handlerInterfaces = handlerTypeInterfaces.Where
(
r => r.IsGenericType && r.GetGenericTypeDefinition() == typeof(IGameResponder<>)
);
foreach (var handlerInterface in handlerInterfaces)
{
serviceCollection.AddScoped(handlerInterface, gameResponder);
}
return serviceCollection;
}
}