C#C
C#5mo ago
Wasted

Execute code in API Controller from a razor page

I have API controllers that are work just fine
I'm trying to execute similar code via another class
Is something being sent to the API controler constructor? If so what and can I send the same thing in the razor file?
Or am I going about this the wrong way?

API Controller
[Route("api/account")]
[ApiController]
public class AccountController : ControllerBase
{
    private readonly UserManager<AppUser> _userManager;
    public AccountController(UserManager<AppUser> userManager)
    {
        _userManager = userManager;
    }
    [HttpPost("register")]
...


Class to create user
public class CreateUser
{
    private readonly UserManager<AppUser> _userManager;
    public CreateUser(UserManager<AppUser> userManager)
    {
        _userManager = userManager;
    }
    public async Task Register(RegisterDto registerDto)
    {
        var appUser = new AppUser
        {
            UserName = registerDto.Username,


razor file
private void Register()
    {
CreateUser createUser = new CreateUser();
createUser.Register(
    new RegisterDto
            {
                Username = "dsa",
...


The error I get

There is no argument given that corresponds to the required parameter 'userManager' of 'CreateUser.CreateUser(UserManager<AppUser>)'
Was this page helpful?