Open FergusCoulter opened 3 years ago
This is my comment from Gitter.
There's a BIG problem here though. At the moment the system supports both regular models and Dynamic models that can be constructed without having access to, or knowing the type of the real model. As the constructor that accepts input will never be available for the dynamic models, the behavior will be different depending on which model you use.
Now, in the long run we're looking into abandoning the dynamic models for many reasons. First reason is it will slim down the code base and make it easier to maintain. Secondly stuff like this can be easily implemented, things like:
And all of these things that can't be done on dynamic models. But at the moment it's hard to get a consistent behavior, especially as the manager interface currently only uses the dynamic models.
Given the circumstances this would need to be implemented in conjunction with #1224 which will consolidate the manager models and move away from dynamic models.
Scheduled this for 10.0
but missed that it is dependent on #1224 which we won't have time to complete for 10.0
. Need to move this out of the upcoming release
I'm looking around for a CMS I can easily integrate into an ASP Core project I'm working on. Piranha looks great but this bug has me worried. Am I misunderstanding this or does dependency injection not work for Razor page models at all? Because if dependency injection doesn't work for page models at all then that would be a big problem.
How does a page model acquire services in order to reach out to REST apis or access databases, or even perform logging? Do you store a global reference to the ServiceProvider somewhere and manually create ServiceProvider scopes to instantiate services or something?
If this is a problem is it just for Razor pages? Does DI work using MVC?
@Neutrino-Sunset If you’re talking about this model https://github.com/PiranhaCMS/piranha.core/blob/master/core/Piranha.AspNetCore/Models/SinglePage.cs it is just a simple wrapper that loads the real page model on GET. To inject services into this model just use it as a base class and inject the services you want in the constructor.
This issue is rather about allowing injection into the real CMS model which is completely different and not related to Razor Pages.
Best regards
Piranha 8.4.2
Page Models currently don't allow for Parameterised Constructors and as a result Dependency Injection.
Will only except parameterless constructors.
See Below for more information: