-
Notifications
You must be signed in to change notification settings - Fork 749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes DDRMenu Razor Bug with Dependency Injection #2998
Fixes DDRMenu Razor Bug with Dependency Injection #2998
Conversation
… by mistake in 9.4.0. The page needs to handle both usage of Dependency Injection and the PageContext.Model
I am going to be attaching modules we can use to test this, please don't merge until I mark all my items as tested |
Test Pass - Razor3 Dependency InjectionI created a small DI module using Razor 3 and it appears to not cause any problems on the page using the DDRMenu Razor3 impl. I attached the module for anyone to use on their site to verify as well |
Test Undecided - Simple Razor ModuleI am not 100% sure what the rules are going to be for this test case Dnn.Simple.Samples.Razor3_00.00.02_Install.zip BackgroundThe Activator code was added to force a default instantiation of the Manual Instantiation@using DotNetNuke.Web.DDRMenu;
@using System.Dynamic;
@inherits DotNetNuke.Web.Razor.DotNetNukeWebPage<MyModel>
@{
Model = new MyModel
} Auto InstantiationIn this example the code should automatically create an instance of @using DotNetNuke.Web.DDRMenu;
@using System.Dynamic;
@inherits DotNetNuke.Web.Razor.DotNetNukeWebPage<MyModel>
OptionsIf we decide Auto Instantiation, we will need to add additional rules to handle the problem with DDRMenu. If we decide to force the user to manually instantiate their model then we can go with the PR as implemented |
@ahoefling based on this blog post it looks like manual instantiation was the pattern recommended. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the menu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahoefling I think at this point this is the "right" solution, granted not the full solution for the future of DNN Platform.
The prior architecture change of manual instantiation is NOT a best practice, but it is the pattern that was supported. For DNN 9.4.1 I think we need to restore this functionality as-is, and will then adjust as we learn more in 10.x to improve the pattern to modern and current standards of implementation.
I'll hold on merging though, until you mark cleared the other types. but I believe this is a solid workaround.
Please do not merge this change I just did a pair coding session with @donker and we uncovered some more details on this. I will update the thread later today with more details. I have a change that will make all the scenarios listed above pass and work together on the same page, which was the original desire to adding the |
Quick HistoryDNN has many different razor rendering engines which are different than the actual module platforms that use them
There are 2 different module platforms in DNN that use Razor Engines
The Razor EngineThere is a project called The APIsThere are 2 APIs that are used through the platform and the 3rd party module ecosystem from
Remember these are both deprecated in 11.x Razor3 Module and the Razor EngineThe Razor3 Module pattern handles the render pipeline for you so all you worry about is creating your Consider the following
When the OnPreRender is invoked this snippet will render that file Dnn.Platform/DNN Platform/DotNetNuke.Web.Razor/RazorModuleBase.cs Lines 67 to 74 in 35acaf5
From this point the Dnn.Platform/DNN Platform/DotNetNuke.Web.Razor/RazorEngine.cs Lines 113 to 123 in 35acaf5
It has been a best practice in DNN We tried to add defensive code in the Dnn.Platform/DNN Platform/DotNetNuke.Web.Razor/DotNetNukeWebPage.cs Lines 63 to 67 in 35acaf5
All of this actually works RazorHost ControlI really don't know much about the RazorHost Control, but here are my findings The RazorHost Control is NOT technically a Razor3 Module in a pure sense of the term DNN Module. It goes around the initial rendering logic and uses the Dnn.Platform/DNN Platform/DotNetNuke.Web.Razor/RazorHostControl.cs Lines 68 to 78 in 35acaf5
DDRMenu and 3rd Party ModulesThere are many 3rd party modules out there including the DDRMenu (which is now a core module) that utilize the Instead of calling the render method that passes Dnn.Platform/DNN Platform/Modules/DDRMenu/TemplateEngine/RazorTemplateProcessor.cs Lines 62 to 63 in 35acaf5
Remember ALL of this is deprecated for 11.x The SolutionSince we need to handle these different usages of the
The downside to this technique is anyone using the RazorEngine WILL NOT get Dependency Injection. Which is fine in my opinion since that isn't really a module pattern, it is just using the rendering engine. |
@ahoefling I would agree with your assessment, using RazorEngine as a rendering engine doesn't need DI |
…el; Swapped Model Accessor to check the PageContext.Model first for a model and if that is null use this classes _model instantiation
6d599cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur with what Andrew stated above. We worked this issue today and verified a few divergent use cases which passed. The term "Razor3" was new to me as we never used that in the DNN ecosystem. But I'll happily defer to authority in Andrew. So my suggestion is to merge this asap so it will go out with 9.4.1.
Hello, |
@alenxmedia this was resolved in 9.4.1, which is not yet released. Have you tried the RC and still encountering issues? Otherwise the 9.4.1 release is coming soon |
Hello, |
Fixes: #2997
Summary
The DDRMenu supports multiple types of rendering engines. The razor engine which uses
.cshtml
files leverages the DNN Razor3 Module Platform. When we implemented Dependency Injection for 9.4.0 this was added to every module platform including the Razor3 Module Pattern (which is used by DDRMenu Razor).The problem
When running a page that uses DNN 9.4.0 the Razor Menu would completely disappear, which is documented in #2997. This was discovered when installing the default theme for nvQuickTheme.
Screenshot
Copied screenshot from #2997 for convenience
The Fix
In DNN 9.4.0 we updated the constructor of any Razor3 module's
DotNetNukeWebPage<T>
to resolve the model if it is included in the IoC DependencyProvider. This provides simple DependencyInjection for this deprecated module pattern.As part of this change, we decided to create a default instantiation of the Model if it isn't registered in the DependencyProvider. This default instantiation causes the crash.
Removing the default instantiation appears to fix the problem
Testing
I have followed the exact same testing steps highlighted in #2997. I do not have any other Razor3 modules to test. We should really test a non DDRMenu Razor3 module to validate it still works
My List of Modules to Test