PiranhaCMS / piranha.core

Piranha CMS is the friendly editor-focused CMS for .NET that can be used both as an integrated CMS or as a headless API.

Home Page:http://piranhacms.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accessing IDb instance from model class

albjerto opened this issue · comments

Piranha version: 10.0.2
.NET 6

I have a Model class for a page in Piranha:

public class MyPage : Page<MyPage>
{

    //...

    [Region]
    public IList<String> Roles { get; set; }
}

The Roles region should contain all the names of the user roles defined in the manager.
In order to obtain this list, I should make use of the static RolesListModel.Get() method, which requires a Piranha.AspNetCore.Identity.IDb.

How do I access the IDb instance from the page model? I managed to do the same with a controller leveraging Dependency Injection, but I cannot do it with the model class.

commented

Hi, I need more info.

Hi there! There is no constructor invocation that allows for dependency injection supported in Piranha atm, so you need to load the related data "on the side" like you did with the controller.

Regards