Dnn.Platform: DI stopped working after 9.4.0 update
Hello.
I have updated a project that was using DNN 9.3.2 to 9.4.0 and my site has blown up with errors on all MVC controllers.
I tracked the problem to the dependency resolver not being able to resolve a dependecy. This is the constructor for one of the controllers that has stopped working.
public DefaultController(ITabService tabService)
I am using simple injector as dependency manager and have so in the past with no problems. The code for my simple injector container registration is this:
Container container = new Container();
container.Register<ITabService, TabService>(mixedScopeLifestyle);
container.Verify();
DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
From what I can tell, the new DNN 9.4.0 has introduced it’s own DI and my guess is that it’s messing with my implementation.
Is this expected behavior? I saw no mention of this issue anywhere.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (9 by maintainers)
@ahoefling that’s great news.
I am using both MVC modules and Web API, that’s why I am registering the container twice (one statement for each). I will provide you with a code sample on monday when I get back to work if I can’t get it sooner.
Thanks for the helping me trying to sort this out.
@jsbsantos Let’s see what we can do to solve this problem, it will be a feature request and not necessarily a bug so depending where we land this might be something that doesn’t get merged until 10.x. If we can add support to this without making any breaking changes with minimal risk I will push to get it in 9.x (all depends on the final solution we land on).
I have read through the SimpleInjector documentation you shared several times, and even pulled their codebase that is being used for the
ServiceCollectionExtension method. At first glance this looks like something that should work, but I think I might know where DNN is running into problems.As a general rule DNN should support
IServiceCollectionextension methods like this in theIDnnStartupas these are the recommended extension points in the library which will simplify the .NET Migration.My Working Theory
I believe we just haven’t implemented support for what you are requesting, as all module patterns strictly use constructor injection. In the module pipeline we manually resolve the dependencies and construct the Controller for example.
I think we may be able to solve this problem, but I am going to need more information
What I Need
I need you to provide me a working code sample of the problem you are seeing with SimpleInjector which is not a code snippet here. I need an installer file so I can install it in a DNN website and the solution of demo project. If you can provide details on the features you are expecting to work as well and what isn’t working now.
With that code sample, I can really investigate and research to provide appropriate recommendations