Some services are not able to be constructed Error while validating the service descriptor Lifetime: Scoped Unable to resolve service for type

Viewed 39

my usermanager services is :

public class UserManagerService : IUserManagerService
{
    private readonly UserManager<UserModel> userManager;
    private readonly UserServiceHelper userServiceHelper;

    public UserManagerService(UserManager<UserModel> _userManager)
    {
        this.userManager = _userManager;
        userServiceHelper = new UserServiceHelper();
    }

    public async Task<bool> CreateUser(UserViewModel user)
    {
        try
        {
            var new_user = userServiceHelper.GetNewItems(user);
            
            await userManager.CreateAsync(new_user);

            return true;
        }
        catch(Exception e)
        {
            throw;  
        }
    }

IUsermanagerServices interface is :

public interface IUsermanagerServices
{
    Task<bool> CreateUser(UserViewModel user);

    Task<bool> CreateUserBatch(List<UserViewModel> users);

    Task<bool> DeleteUser(UserViewModel user);
}

And userapicontroller is :

[Route("api/[controller]")]
[ApiController]
public class UserApiController : ControllerBase
{
    private readonly IUserManagerService userManager;
    
    public UserApiController(IUserManagerService _userManager)
    {
        userManager = _userManager;
    }

    [HttpPost]
    public async Task<IActionResult> Post([FromBody] List<UserViewModel> users)
    {
        try
        {
            var _result = await userManager.CreateUserBatch(users);

            var _response = new ResponseModel<bool>()
            {
                Content = _result,
                Message = "np"
            };
            
            return Ok(_response);
        }
        catch(Exception e)
        {
            var _response = new ResponseModel<bool>()
            {
                Content = false,
                ExceptionMessage = e.Message,
                HasError = true
            }.ToString();
            
            return Problem(_response);
        }            
    }

service extension is :

public static void AddUserManagerServices(this IServiceCollection services)
{
    services.AddScoped<IUserManagerService, UserManagerService>();
}

and program :

#region 
builder.Services.AddUserManagerServices();
#endregion

var app = builder.Build();

in this last line i have exception

Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Lifetime: Scoped ImplementationType: Unable to resolve service for type while attempting to activate)

how can i fix it ?

0 Answers
Related