Skip to content

Duplicates when Scanning Assemblies with latest .NET 7 SDK versions #200

@markreed-hearst

Description

@markreed-hearst

Hi,
We are using Scrutor as part of our .NET Core Web Api implementation. The following code is used to scan dependencies of the api and register implementations of the handler interfaces:

internal static IServiceCollection AutoRegisterHandlers(this IServiceCollection services) { services.Scan(scan => scan.FromApplicationDependencies() .AddClasses(classes => classes.AssignableTo<IHandleGetRequests>()).As<IHandleGetRequests>() .AddClasses(classes => classes.AssignableTo<IHandleDeleteRequests>()).As<IHandleDeleteRequests>() .AddClasses(classes => classes.AssignableTo(typeof(IHandlePatchRequests<>))).AsImplementedInterfaces() .AddClasses(classes => classes.AssignableTo(typeof(IHandlePutRequests<>))).AsImplementedInterfaces() .AddClasses(classes => classes.AssignableTo(typeof(IHandlePostRequests<>))).AsImplementedInterfaces()); return services; }

With version 7.0.100 of the .NET SDK the above code works as expected and the results of the call to services.Scan include one entry for each implementation of the interfaces. However after upgrading the SDK to 7.0.2** (e.g. the latest version 7.0.203) then the assembly scanning produces duplicates for each interface, this in turn creates duplicates in our registration of the handlers and results in Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints errors at runtime.

We are aware of the RegistrationStrategy stuff and we are looking at amending our code to make use of this with either Skip or Replace but wanted to check if you are aware of the issue and whether there are any plans to release an update of Scrutor in response to this or not?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions