That article pointed out some problems that could arise because models are cached. So perhaps I will do something else, a controller seems heavy-handed for my situation, so ended up just putting more in the top of the view. Perhaps I should look at react I hear that combines all your view and logic together, and I should just embrace the idea.
Thanks for the suggestion Dave,
Currently, I am injecting the dependency into the view and passing it as a parameter to the relevant method on the ModelsBuilder Class.
It's a little clunky, but I will stick with that rather than add an additional dependency.
How do I inject dependencies into a ModelsBuilder Partial?
I would like to use some dependencies in a ModelsBuilder partial class. How do I do that?
Hi Murray,
That is not possible. The models generated have a constructor that can't be changed.
See the documentation : https://our.umbraco.com/Documentation/Reference/Templating/Modelsbuilder/Understand-And-Extend#extending
There is a new modelsbuilder package released not so long ago : https://our.umbraco.com/packages/developer-tools/limbo-models-builder/
Maybe this has the option to do this. I did not check it out yet.
Dave
That article pointed out some problems that could arise because models are cached. So perhaps I will do something else, a controller seems heavy-handed for my situation, so ended up just putting more in the top of the view. Perhaps I should look at react I hear that combines all your view and logic together, and I should just embrace the idea.
Hi Murray,
I just checked out the documentation of that package. It's possible to tweak the models generation with notification handlers.
https://github.com/limbo-works/Limbo.Umbraco.ModelsBuilder#getmodelsnotification
Maybe that will work for you.
Dave
Thanks for the suggestion Dave, Currently, I am injecting the dependency into the view and passing it as a parameter to the relevant method on the ModelsBuilder Class. It's a little clunky, but I will stick with that rather than add an additional dependency.
Thanks Again.
Murray.
is working on a reply...