I'm trying to write a new method on ServerMethodsController.Custom.cs that needs to fetch all users with a given role, but I'm having a hard time figuring it out. How can this be achieved?
How can I access the userManager and roleManager from a method on ServerMethodsController.Custom.cs?
Nice. What else can be injected? I didn't find anything about that in the docs.
However, in reality, I needed that in an Entity controller trigger (OnMyEntityCreated), but when I create another constructor in the MyEntityController.Custom.cs partial class and run the app, it throws an exception: Multiple constructors accepting all given argument types have been found in type 'MyApp.Controllers.MySql.MyEntityController'. There should only be one applicable constructor.
public partial class OrcamentosController
{
private readonly UserManager<ApplicationUser> userManager;
private readonly RoleManager<IdentityRole> roleManager;
public MyEntityController(MySqlContext context, UserManager<ApplicationUser> userManager, RoleManager<IdentityRole> roleManager) : this(context)
{
this.userManager = userManager;
this.roleManager = roleManager;
}
Yes, but I couldn't find an answer...
I wasn't familiar with ASP.NET Core dependency injection and still don't fully understand it.
I get no troubles creating a constructor with all the dependencies I need in a ServerMethodsController. But what I really need is to inject those dependencies in an entity controller. Since the entity controller already has a default controller receiving the DB context, when I create another constructor in my custom partial class with all the dependencies I need, it throws that runtime exception I mentioned.
The use case is: When a user creates an Order, I want the server to send an email to all users with a given role.
How can I achieve this?