CleanArchitecture.WebApi icon indicating copy to clipboard operation
CleanArchitecture.WebApi copied to clipboard

userManager in AccountService is null

Open yozawiratama opened this issue 1 year ago • 0 comments

Describe the bug I tried to re-create this to dotnet core 6 for my project, I believe nothing wrong with my code becuase I tried to copy and paste and modify one by one. but when I try for register, _userManager is null

Expected behavior _userManager in AccountService is populated or not null

Screenshots Screen Shot 2022-07-26 at 19 34 22

Desktop (please complete the following information):

  • OS: Mac
  • Browser Chrome

Additional context this is my program.cs in web api

using Application;
using Application.Interfaces;
using Infrastructure.Identity;
using Infrastructure.Persistence;
using Infrastructure.Identity.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Readbuk.Api.Services;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddApplication();

builder.Services.AddIdentityInfrastructure(builder.Configuration);
builder.Services.AddPersistenceInfrastructure(builder.Configuration);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IAuthenticatedUserService, AuthenticatedUserService>();

#region API Versioning
// Add API Versioning to the Project
builder.Services.AddApiVersioning(config =>
{
    // Specify the default API Version as 1.0
    config.DefaultApiVersion = new ApiVersion(1, 0);
    // If the client hasn't specified the API version in the request, use the default API version number 
    config.AssumeDefaultVersionWhenUnspecified = true;
    // Advertise the API versions supported for the particular endpoint
    config.ReportApiVersions = true;
});
#endregion

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
    var scopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();
    using (var scope = scopeFactory.CreateScope())
    {
        var roleManager = scope.ServiceProvider.GetRequiredService<RoleManager<IdentityRole>>();
        var userManager = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
        //await DefaultRoles.SeedAsync(userManager, roleManager);
        //await DefaultBasicUser.SeedAsync(userManager, roleManager);
        //await DefaultSuperAdmin.SeedAsync(userManager, roleManager);
    }
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();


yozawiratama avatar Jul 26 '22 12:07 yozawiratama