jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
11k stars 1.16k forks source link

MediatR.Extensions.DependencyInjection functionality #862

Closed zoinkydoink closed 1 year ago

zoinkydoink commented 1 year ago

I had the following where I would pass System.Type[] and the array could contain types from 2 different assemblies. I see that the DI dll is now part of Mediatr 12.0>

How can I maintain this functionality and be able to pass types from multiple assemblies?

    services.AddMediatR(type); // where type is Type[]

Edit: Is this the preferred way to achieve my goal?

    services.AddMediatR(cfg =>
            {
                foreach (var type in types)
                {
                    cfg.RegisterServicesFromAssemblies(Assembly.GetAssembly(type));
                }
        });
jbogard commented 1 year ago

Yes, that overload does not exist at the moment. You can do this:

services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(types.Select(t => t.Assembly)));
zoinkydoink commented 1 year ago

Thank you, that will do