I am working on a legacy ASP.NET application with target framework .NET 4.7.2. There is already a Unity container implemented (using Microsoft.AspNet.WebFormsDependencyInjection.Unity
v1.0.0). Now, I want to use Mediatr with the same unity container implementation. Is this feasible?
The following NuGet packages are used:
- Microsoft.AspNet.WebFormsDependencyInjection.Unity v1.0.0
- Unity v4.0.1
- Unity.Abstractions v3.3.0
- Unity.Container v5.8.6
- Unity.WebForms v1.4.0
Here is the code to register dependency with unity container
public class Global : System.Web.HttpApplication
{
public void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
IdentityModelEventSource.ShowPII = true;
// Code for dependency injection
var diContainer = this.AddUnity();
diContainer.RegisterType<MyServices>(new TransientLifetimeManager());
diContainer.RegisterType<IUnitOfWork, UnitOfWork>(new TransientLifetimeManager());
diContainer.RegisterType<MapperConfig>(new ContainerControlledLifetimeManager());
// Services
diContainer.RegisterType<DashboardService>(new TransientLifetimeManager());
diContainer.RegisterType<UserVisitsService>(new TransientLifetimeManager());
diContainer.RegisterType<MyBasePage>(new InjectionConstructor(diContainer.Resolve<MyServices>()));
diContainer.RegisterType<UnifiedSite>(new InjectionConstructor(typeof(MyServices), typeof(NavigationService)));
// Web API controllers
diContainer.RegisterType<Controllers.DashboardController>(new InjectionConstructor(diContainer.Resolve<DashboardService>()));
diContainer.RegisterType<Controllers.FeedbackController>(new InjectionConstructor(diContainer.Resolve<IUnitOfWork>()));
diContainer.RegisterType<Controllers.UserVisitsController>(new InjectionConstructor(diContainer.Resolve<UserVisitsService>()));
GlobalConfiguration.Configuration.DependencyResolver = new UnityIoCContainer(diContainer);
}
}
Please guide me if anyone has used MediatR with .NET 4.7.2. If you can share a Github repository for sample code it will really help.