jbogard / MediatR.Extensions.Microsoft.DependencyInjection

MediatR extensions for Microsoft.Extensions.DependencyInjection
MIT License
326 stars 90 forks source link

Ambiguous match found #103

Open ClementeGao opened 3 years ago

ClementeGao commented 3 years ago
public class Test1Handler : BaseHander<Entity1>
{

}
public class Test2Handler : BaseHander<Entity2>
{

}

 public class BaseHander<TEntity>:IRequestHandler<UpdateSubmitCommand, Result>,
        IRequestHandler<DeleteCommand, Result>,
        IRequestHandler<UpdateRowStatusCommand, Result>
{
      public virtual async Task<Result> Handle(UpdateRowStatusCommand request, CancellationToken cancellationToken) =>throw new NotImplementedException()
      public virtual async Task<Result> Handle(UpdateSubmitCommand request, CancellationToken cancellationToken) =>throw new NotImplementedException()
      public virtual async Task<Result> Handle(DeleteCommand request, CancellationToken cancellationToken) =>throw new NotImplementedException()
} 

public class Startup
{
     public void ConfigureServices(IServiceCollection services)
       {
           services.AddMediatR(typeof(Startup).Assembly);
       }
}

when i setup program it have a error

System.Reflection.AmbiguousMatchException: Ambiguous match found. at System.RuntimeType.GetInterface(String fullname, Boolean ignoreCase) at System.Type.GetInterface(String name) at MediatR.Registration.ServiceRegistrar.IsMatchingWithInterface(Type handlerType, Type handlerInterface) in D:\Clement\projects\sourcecodes\MediatR.Extensions.Microsoft.DependencyInjection-master\src\MediatR.Extensions.Microsoft.DependencyInjection\Registration\ServiceRegistrar.cs:line 126 at MediatR.Registration.ServiceRegistrar.<>cDisplayClass1_0.b3(Type m) in D:\Clement\projects\sourcecodes\MediatR.Extensions.Microsoft.DependencyInjection-master\src\MediatR.Extensions.Microsoft.DependencyInjection\Registration\ServiceRegistrar.cs:line 94 at System.Collections.Generic.List1.RemoveAll(Predicate1 match) at MediatR.Registration.ServiceRegistrar.ConnectImplementationsToTypesClosing(Type openRequestInterface, IServiceCollection services, IEnumerable1 assembliesToScan, Boolean addIfAlreadyExists) in D:\Clement\projects\sourcecodes\MediatR.Extensions.Microsoft.DependencyInjection-master\src\MediatR.Extensions.Microsoft.DependencyInjection\Registration\ServiceRegistrar.cs:line 94 at MediatR.Registration.ServiceRegistrar.AddMediatRClasses(IServiceCollection services, IEnumerable1 assembliesToScan) in D:\Clement\projects\sourcecodes\MediatR.Extensions.Microsoft.DependencyInjection-master\src\MediatR.Extensions.Microsoft.DependencyInjection\Registration\ServiceRegistrar.cs:line 17 at MediatR.ServiceCollectionExtensions.AddMediatR(IServiceCollection services, IEnumerable1 assemblies, Action1 configuration) in D:\Clement\projects\sourcecodes\MediatR.Extensions.Microsoft.DependencyInjection-master\src\MediatR.Extensions.Microsoft.DependencyInjection\ServiceCollectionExtensions.cs:line 60 at MediatR.ServiceCollectionExtensions.AddMediatR(IServiceCollection services, Assembly[] assemblies) in D:\Clement\projects\sourcecodes\MediatR.Extensions.Microsoft.DependencyInjection-master\src\MediatR.Extensions.Microsoft.DependencyInjection\ServiceCollectionExtensions.cs:line 29 at SaleManage.ApiHost.Startup.ConfigureServices(IServiceCollection services) in D:\NX\projects\backEnd\dbn.microservices\SaleManagement\SaleManage\src\SaleManage.ApiHost\Startup.cs:line 187 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>cDisplayClass9_0.gStartup|0(IServiceCollection serviceCollection) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>cDisplayClass8_0.b0(IServiceCollection services) at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance) at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>cDisplayClass13_0.b0(HostBuilderContext context, IServiceCollection services) at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider() at Microsoft.Extensions.Hosting.HostBuilder.Build()

How can I change my code i need your help thank you