ITIXO / MediatR.Extensions.AttributedBehaviors

MIT License
28 stars 5 forks source link

Register Multiple Assemblies #4

Open ardalis opened 1 year ago

ardalis commented 1 year ago

We're trying to apply attribute-based behaviors to IRequest types that are defined in a Shared project. However, the call to wire up AttributedBehaviors only accepts a single assembly. After trying to figure out why our behaviors weren't working, we tried moving our IRequest type to the web project and suddenly it started working. I'm assuming this is because we have this in our code:

  services.AddMediatRAttributeBehaviors(executingAssembly);

MediatR accepts a collection of assemblies to scan; can we follow the same pattern for this project, so that we could pass in the executing assembly as well as the shared project's assembly?

Thanks!

vaclavholusa commented 1 year ago

Hi @ardalis, thanks for the comment. Yes that would absolutely make sense. Would you be able to contribute and open PR?

ardalis commented 1 year ago

Perhaps but I'm not sure if or when I'll find time for it.

htxryan commented 1 year ago

Perhaps I'm missing something, but this looks like it's already supported (and has been since 2021). AddMediatRAttributeBehaviors() has an overload that accepts an IEnumerable of assemblies: https://github.com/ITIXO/MediatR.Extensions.AttributedBehaviors/blob/main/src/MediatR.Extensions.AttributedBehaviors/ServiceCollectionExtensions.cs#L15