alsami / MediatR.Extensions.Autofac.DependencyInjection

Autofac plug-in for MediatR.
MIT License
55 stars 14 forks source link

v9.2 Incompatible with Mediatr v12 - changes to ServiceFactory #17

Closed jafin closed 1 year ago

jafin commented 1 year ago

Changes in Mediatr v12 resolving ServiceFactory have impacted compatibility with this library v9.2.

I had a look, but admit I got lost in implementing the changes required to this library to attempt a PR.

From their repo: https://github.com/jbogard/MediatR/wiki/Migration-Guide-11.x-to-12.0

Leveraging Microsoft.Extensions.DependencyInjection.Abstractions directly The Mediator class now references IServiceProvider directly, instead of the previous custom delegate:

-    public Mediator(ServiceFactory serviceFactory) 
-        => _serviceFactory = serviceFactory;
+    public Mediator(IServiceProvider serviceProvider) 
+        : this(serviceProvider, new ForeachAwaitPublisher()) { }
+    public Mediator(IServiceProvider serviceProvider, INotificationPublisher publisher)
+    {
+        _serviceProvider = serviceProvider;
+        _publisher = publisher;
+    }

The ServiceFactory delegate was removed:

-public delegate object ServiceFactory(Type serviceType);

The functionality of MediatR.Extensions.DependencyInjection.Abstractions is now folded in directly to MediatR itself, so you can remove the reference to the extensions package and call the MediatR package directly:

services.AddMediatR(/* registration */);

For codebases not using the extension package, you may either implement IServiceProvider directly, or for many containers, they already directly support IServiceProvider directly.

alsami commented 1 year ago

10.0.0 of this package should be up in a few minutes.

Please check out the changelog.

Feedback most welcome!

jafin commented 1 year ago

Thanks @alsami much appreciated