/// <summary> /// Adds NotSoAutoMapper functionality. /// </summary> /// <param name="registerSingletonService">The delegate to use to register a singleton in the IoC container.</param> public static void AddNotSoAutoMapper(RegisterSingletonService registerSingletonService) { if (registerSingletonService is null) { throw new ArgumentNullException(nameof(registerSingletonService)); } // Nothing for now. }
/// <summary> /// Registers the mapper of the specified <paramref name="mapperType" />. It must implement /// <see cref="IMapper{TInput,TResult}" />. /// If it implements multiple generic versions of it, all of them are registered. /// </summary> /// <param name="mapperType">The type of the mapper.</param> /// <param name="registerSingletonService">The delegate to use to register a singleton in the IoC container.</param> /// <exception cref="InvalidOperationException"> /// When the mapper does not implement <see cref="IMapper{TInput,TResult}" /> /// </exception> public static void AddMapper(Type mapperType, RegisterSingletonService registerSingletonService) { if (mapperType is null) { throw new ArgumentNullException(nameof(mapperType)); } var mapperInterfaces = mapperType.FindInterfaces((t, _) => IsGenericTypeFromUnbound(t, typeof(IMapper <,>)), null); if (!mapperInterfaces.Any()) { throw new InvalidOperationException($"The type {mapperType} does not implement IMapper."); } foreach (var mapperInterface in mapperInterfaces) { registerSingletonService(mapperInterface, mapperType); } }