skip to Main Content

I am trying to migrate from .NET CORE 3 Web API to .NET CORE 7 Web API, here is my program.cs code:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSpaStaticFiles(configuration =>
{
    configuration.RootPath = "ClientApp/dist";
});
// Add services to the container.

// builder.Services.Configure<ApplicationDbContext>(builder.Configuration.GetSection("DatabaseConnectionString"));
builder.Services.AddCustomizedMvc();
builder.Services.AddCustomAutoMapper();

builder.Services.AddDbContext();

builder.Services.AddControllers();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();


builder.Services.AddCors(option =>
   option.AddPolicy("AllowAll", p =>
       p.AllowAnyOrigin()
        .AllowAnyMethod()
        .AllowAnyHeader()
   )
);



builder.Services.AddCustomAuthentication();
builder.Services.AddCustomAuthorization();

builder.Services.AddCustomIdentity();
builder.Services.AddMvc(options => options.EnableEndpointRouting = false);


builder.Services.Configure<FormOptions>(x =>
            {
                // set MaxRequestBodySize property to 200 MB
                x.MultipartBodyLengthLimit = 209715200;
            });

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI(c =>
            {
                c.RoutePrefix = AppSettings.Instance.SwaggerRoutePrefix;
                c.SwaggerEndpoint("/swagger/doc/swagger.json", "doc");
            });


    app.UseDeveloperExceptionPage();
}
EmailTemplates.Initialize(app.Environment);


Estato.Core.ServiceProvider.Services = app.Services;

var tempOptions = new RewriteOptions();
tempOptions.AddRedirectToWww();
app.UseRewriter(tempOptions);

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Storage")),
    RequestPath = new PathString("/Storage")
});
app.UseAuthorization();
app.UseAuthentication();
app.UseCors("AllowAll");
app.UseMvc();

app.UseSpa(spa =>
{

    
    spa.Options.SourcePath = "ClientApp";
    
    if (app.Environment.IsDevelopment())
    {
        spa.UseAngularCliServer(npmScript: "start");
        spa.Options.StartupTimeout = TimeSpan.FromSeconds(120); // Increase the timeout if angular app is taking longer to startup
                                                                //spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); // Use this instead to use the angular cli server
    }

});
app.UseHttpsRedirection();
app.MapControllers();
app.Run();

and here is ServiceCollectionExtensions code:

 namespace Estato.Core.Extensions
 {
    public static class ServiceCollectionExtensions
    {
        private const string SecretKey = "iNivDmHLpUA223sqsfhqGbMRdRj1PVkH";
        private static readonly SymmetricSecurityKey _signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(SecretKey));

        public static IServiceCollection AddCustomAuthentication(this IServiceCollection services)
        {
            var jwtAppSettingOptions = AppSettings.Instance.JwtIssuerOptions;
            if (jwtAppSettingOptions == null)
            {
                // Handle the scenario where JwtIssuerOptions is null
                // For example, you could log an error or throw an exception.
                throw new Exception("JwtIssuerOptions is null. Check the configuration.");
            }
            services.Configure<JwtIssuerOptions>(options =>
            {
                options.Issuer = jwtAppSettingOptions.Issuer;
                options.Audience = jwtAppSettingOptions.Audience;
                options.SigningCredentials = new SigningCredentials(_signingKey, SecurityAlgorithms.HmacSha256);
            });

            var tokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer = true,
                ValidIssuer = jwtAppSettingOptions.Issuer,

                ValidateAudience = true,
                ValidAudience = jwtAppSettingOptions.Audience,

                ValidateIssuerSigningKey = true,
                IssuerSigningKey = _signingKey,

                RequireExpirationTime = false,
                ValidateLifetime = true,
                ClockSkew = TimeSpan.Zero
            };

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;

            }).AddJwtBearer(configureOptions =>
            {
                configureOptions.ClaimsIssuer = jwtAppSettingOptions.Issuer;
                configureOptions.TokenValidationParameters = tokenValidationParameters;
                configureOptions.SaveToken = true;
            });

            return services;
        }

        public static IServiceCollection AddCustomAuthorization(this IServiceCollection services)
        {
            services.AddAuthorization(options =>
            {
                #region  User
                options.AddPolicy(Policies.ManageUsers, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.USER_CRUD));
                options.AddPolicy(Policies.ManageRoles, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.ROLE_CRUD));
                #endregion

                #region Manual
                options.AddPolicy(Policies.ManageAppliancies, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.APPLIANCE_CRUD));
                options.AddPolicy(Policies.ManageArchitecturalStyles, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.ARCHITECTURAL_STYLE_CRUD));
                options.AddPolicy(Policies.ManageBasements, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BASEMENT_CRUD));
                options.AddPolicy(Policies.ManageBuildActions, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BUILD_ACTION_CRUD));
                options.AddPolicy(Policies.ManageBuildTechnologies, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BUILD_TECHNOLOGY_CRUD));
                options.AddPolicy(Policies.ManageBuildTypes, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BUILD_TYPE_CRUD));
                options.AddPolicy(Policies.ManageBuildTypeGroups, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BUILD_TYPE_GROUP_CRUD));
                options.AddPolicy(Policies.ManageCities, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.CITY_CRUD));
                options.AddPolicy(Policies.ManageClientTypes, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.CLIENT_TYPE_CRUD));
                options.AddPolicy(Policies.ManageCoolingTypes, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.COOLING_TYPE_CRUD));
                options.AddPolicy(Policies.ManageCountries, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.COUNTRY_CRUD));
                options.AddPolicy(Policies.ManageDimensions, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.DIMENSION_CRUD));
                options.AddPolicy(Policies.ManageDistricts, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.DISTRICT_CRUD));
                options.AddPolicy(Policies.ManageExteriors, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.EXTERIOR_CRUD));
                options.AddPolicy(Policies.ManageFloorCoverings, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.FLOOR_COVERING_CRUD));
                options.AddPolicy(Policies.ManageHeatingFuels, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.HEATING_FUEL_CRUD));
                options.AddPolicy(Policies.ManageHeatingTypes, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.HEATING_TYPE_CRUD));
                options.AddPolicy(Policies.ManageIndoorFeatures, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.INDOOR_FEATURE_CRUD));
                options.AddPolicy(Policies.ManageMetroKeys, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.METRO_KEY_CRUD));
                options.AddPolicy(Policies.ManageMoneyTypes, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.MONEY_TYPE_CRUD));
                options.AddPolicy(Policies.ManageOutdoorAmenities, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.OUTDOOR_AMENITY_CRUD));
                options.AddPolicy(Policies.ManageOwnerTypes, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.OWNER_TYPE_CRUD));
                options.AddPolicy(Policies.ManageParkings, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.PARKING_CRUD));
                options.AddPolicy(Policies.ManageRegions, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.REGION_CRUD));
                options.AddPolicy(Policies.ManageRoofTypes, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.ROOF_TYPE_CRUD));
                options.AddPolicy(Policies.ManageRooms, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.ROOM_CRUD));
                options.AddPolicy(Policies.ManageSizeNames, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.SIZE_NAME_CRUD));
                options.AddPolicy(Policies.ManageViews, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.VIEW_CRUD));
                options.AddPolicy(Policies.ManageZones, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.ZONE_CRUD));
                #endregion

                #region Common
                options.AddPolicy(Policies.ManageBuildAllRoom, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BUILD_ALL_ROOM_CRUD));
                options.AddPolicy(Policies.ManageBuildFeatures, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BUILD_FEATURE_CRUD));
                options.AddPolicy(Policies.ManageBuildings, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BUILDING_CRUD));
                options.AddPolicy(Policies.ManageBuildMedia, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BUILD_MEDIA_CRUD));
                options.AddPolicy(Policies.ManageBuildPhoto, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BUILD_PHOTO_CRUD));
                options.AddPolicy(Policies.ManageBuildZoneAll, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.BUILD_ZONE_ALL_CRUD));
                options.AddPolicy(Policies.ManageCheckingAccount, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.CHECKING_ACCOUNT_CRUD));
                options.AddPolicy(Policies.ManageLocation, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.LOCATION_CRUD));
                options.AddPolicy(Policies.ManageNeighborhood, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.NEIGHBORHOOD_CRUD));
                options.AddPolicy(Policies.ManageOpenDay, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.OPEN_DAY_CRUD));
                options.AddPolicy(Policies.ManagePhoneNode, policy => policy.RequireClaim(ClaimTypes.Permission, Permissions.PHONE_NODE_CRUD));
                #endregion
            });


            return services;
        }



        public static IServiceCollection AddCustomIdentity(this IServiceCollection services)
        {
            var builder = services.AddIdentityCore<User>(o =>
            {
                // configure identity options
                o.Password.RequireDigit = false;
                o.Password.RequireLowercase = false;
                o.Password.RequireUppercase = false;
                o.Password.RequireNonAlphanumeric = false;
                o.Password.RequiredLength = 6;
                o.SignIn.RequireConfirmedEmail = true;
            });

            builder = new IdentityBuilder(builder.UserType, typeof(Role), builder.Services);
            builder.AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();

            return services;
        }

        public static IServiceCollection AddDbContext(this IServiceCollection services)
        {
            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseLazyLoadingProxies()
                       .UseSqlServer(AppSettings.Instance.DatabaseConnectionString)
                       .EnableSensitiveDataLogging());

            // services.AddDbContext<ApplicationDbContext>(options =>
            //     options.UseLazyLoadingProxies()
            //            .UseNpgsql(AppSettings.Instance.DatabaseConnectionString, o => o.UseNetTopologySuite())
            //            .EnableSensitiveDataLogging());

            return services;
        }

        public static IServiceCollection AddCustomAutoMapper(this IServiceCollection services)
        {

            services.AddAutoMapper(typeof(Program));
            AutoMapperConfiguration.Configure();

            return services;
        }

        public static IServiceProvider ConfigureAutofac(this IServiceCollection services, Autofac.IContainer container)
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new AutofacModule());
            builder.Populate(services);
            container = builder.Build();

            return new AutofacServiceProvider(container);
        }

        public static IServiceCollection AddCustomizedMvc(this IServiceCollection services)
        {
            services.AddMvc()
                    .AddControllersAsServices()
                    .AddJsonOptions(options =>
                    {
                        options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
                       
                    });

            return services;
        }


    }
}

here is error :

Unhandled exception. System.AggregateException: Some services are not
able to be constructed (Error while validating the service descriptor
‘ServiceType: Estato.Controllers.AuthController Lifetime: Transient
ImplementationType: Estato.Controllers.AuthController’: Unable to
resolve service for type ‘Estato.Core.Security.IJwtFactory’ while
attempting to activate ‘Estato.Controllers.AuthController’.) (Error
while validating the service descriptor ‘ServiceType:
Estato.Controllers.BuildingController Lifetime: Transient
ImplementationType: Estato.Controllers.BuildingController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.BuildingService’
while attempting to activate ‘Estato.Controllers.BuildingController’.)
(Error while validating the service descriptor ‘ServiceType:
Estato.Controllers.CheckingAccountController Lifetime: Transient
ImplementationType: Estato.Controllers.CheckingAccountController’:
Unable to resolve service for type
‘Estato.Core.BLL.Services.CheckingAccountService’ while attempting to
activate ‘Estato.Controllers.CheckingAccountController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.PhoneNodeController Lifetime: Transient
ImplementationType: Estato.Controllers.PhoneNodeController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.PhoneNodeService’
while attempting to activate
‘Estato.Controllers.PhoneNodeController’.) (Error while validating the
service descriptor ‘ServiceType: Estato.Controllers.RoleController
Lifetime: Transient ImplementationType:
Estato.Controllers.RoleController’: Unable to resolve service for type
‘Microsoft.AspNetCore.Identity.RoleManager`1[Estato.Core.DAL.Entities.Role]’
while attempting to activate ‘Estato.Controllers.RoleController’.)
(Error while validating the service descriptor ‘ServiceType:
Estato.Controllers.UserController Lifetime: Transient
ImplementationType: Estato.Controllers.UserController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.UserService’ while
attempting to activate ‘Estato.Controllers.UserController’.) (Error
while validating the service descriptor ‘ServiceType:
Estato.Controllers.ApplianceController Lifetime: Transient
ImplementationType: Estato.Controllers.ApplianceController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.ApplianceService’
while attempting to activate
‘Estato.Controllers.ApplianceController’.) (Error while validating the
service descriptor ‘ServiceType:
Estato.Controllers.ArchitecturalStyleController Lifetime: Transient
ImplementationType: Estato.Controllers.ArchitecturalStyleController’:
Unable to resolve service for type
‘Estato.Core.BLL.Services.ArchitecturalStyleService’ while attempting
to activate ‘Estato.Controllers.ArchitecturalStyleController’.) (Error
while validating the service descriptor ‘ServiceType:
Estato.Controllers.BasementController Lifetime: Transient
ImplementationType: Estato.Controllers.BasementController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.BasementService’
while attempting to activate ‘Estato.Controllers.BasementController’.)
(Error while validating the service descriptor ‘ServiceType:
Estato.Controllers.BuildActionController Lifetime: Transient
ImplementationType: Estato.Controllers.BuildActionController’: Unable
to resolve service for type
‘Estato.Core.BLL.Services.BuildActionService’ while attempting to
activate ‘Estato.Controllers.BuildActionController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.BuildTechnologyController Lifetime: Transient
ImplementationType: Estato.Controllers.BuildTechnologyController’:
Unable to resolve service for type
‘Estato.Core.BLL.Services.BuildTechnologyService’ while attempting to
activate ‘Estato.Controllers.BuildTechnologyController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.BuildTypeController Lifetime: Transient
ImplementationType: Estato.Controllers.BuildTypeController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.BuildTypeService’
while attempting to activate
‘Estato.Controllers.BuildTypeController’.) (Error while validating the
service descriptor ‘ServiceType:
Estato.Controllers.BuildTypeGroupController Lifetime: Transient
ImplementationType: Estato.Controllers.BuildTypeGroupController’:
Unable to resolve service for type
‘Estato.Core.BLL.Services.BuildTypeGroupService’ while attempting to
activate ‘Estato.Controllers.BuildTypeGroupController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.ClientTypeController Lifetime: Transient
ImplementationType: Estato.Controllers.ClientTypeController’: Unable
to resolve service for type
‘Estato.Core.BLL.Services.ClientTypeService’ while attempting to
activate ‘Estato.Controllers.ClientTypeController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.CoolingTypeController Lifetime: Transient
ImplementationType: Estato.Controllers.CoolingTypeController’: Unable
to resolve service for type
‘Estato.Core.BLL.Services.CoolingTypeService’ while attempting to
activate ‘Estato.Controllers.CoolingTypeController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.CountryController Lifetime: Transient
ImplementationType: Estato.Controllers.CountryController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.CountryService’
while attempting to activate ‘Estato.Controllers.CountryController’.)
(Error while validating the service descriptor ‘ServiceType:
Estato.Controllers.DimensionController Lifetime: Transient
ImplementationType: Estato.Controllers.DimensionController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.DimensionService’
while attempting to activate
‘Estato.Controllers.DimensionController’.) (Error while validating the
service descriptor ‘ServiceType: Estato.Controllers.DistrictController
Lifetime: Transient ImplementationType:
Estato.Controllers.DistrictController’: Unable to resolve service for
type ‘Estato.Core.BLL.Services.DistrictService’ while attempting to
activate ‘Estato.Controllers.DistrictController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.ExteriorController Lifetime: Transient
ImplementationType: Estato.Controllers.ExteriorController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.ExteriorService’
while attempting to activate ‘Estato.Controllers.ExteriorController’.)
(Error while validating the service descriptor ‘ServiceType:
Estato.Controllers.FloorCoveringController Lifetime: Transient
ImplementationType: Estato.Controllers.FloorCoveringController’:
Unable to resolve service for type
‘Estato.Core.BLL.Services.FloorCoveringService’ while attempting to
activate ‘Estato.Controllers.FloorCoveringController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.HeatingFuelController Lifetime: Transient
ImplementationType: Estato.Controllers.HeatingFuelController’: Unable
to resolve service for type
‘Estato.Core.BLL.Services.HeatingFuelService’ while attempting to
activate ‘Estato.Controllers.HeatingFuelController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.HeatingTypeController Lifetime: Transient
ImplementationType: Estato.Controllers.HeatingTypeController’: Unable
to resolve service for type
‘Estato.Core.BLL.Services.HeatingTypeService’ while attempting to
activate ‘Estato.Controllers.HeatingTypeController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.IndoorFeatureController Lifetime: Transient
ImplementationType: Estato.Controllers.IndoorFeatureController’:
Unable to resolve service for type
‘Estato.Core.BLL.Services.IndoorFeatureService’ while attempting to
activate ‘Estato.Controllers.IndoorFeatureController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.MetroKeyController Lifetime: Transient
ImplementationType: Estato.Controllers.MetroKeyController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.MetroKeyService’
while attempting to activate ‘Estato.Controllers.MetroKeyController’.)
(Error while validating the service descriptor ‘ServiceType:
Estato.Controllers.MoneyTypeController Lifetime: Transient
ImplementationType: Estato.Controllers.MoneyTypeController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.MoneyTypeService’
while attempting to activate
‘Estato.Controllers.MoneyTypeController’.) (Error while validating the
service descriptor ‘ServiceType:
Estato.Controllers.OutdoorAmenityController Lifetime: Transient
ImplementationType: Estato.Controllers.OutdoorAmenityController’:
Unable to resolve service for type
‘Estato.Core.BLL.Services.OutdoorAmenityService’ while attempting to
activate ‘Estato.Controllers.OutdoorAmenityController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.OwnerTypeController Lifetime: Transient
ImplementationType: Estato.Controllers.OwnerTypeController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.OwnerTypeService’
while attempting to activate
‘Estato.Controllers.OwnerTypeController’.) (Error while validating the
service descriptor ‘ServiceType: Estato.Controllers.ParkingController
Lifetime: Transient ImplementationType:
Estato.Controllers.ParkingController’: Unable to resolve service for
type ‘Estato.Core.BLL.Services.ParkingService’ while attempting to
activate ‘Estato.Controllers.ParkingController’.) (Error while
validating the service descriptor ‘ServiceType:
Estato.Controllers.RegionController Lifetime: Transient
ImplementationType: Estato.Controllers.RegionController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.RegionService’
while attempting to activate ‘Estato.Controllers.RegionController’.)
(Error while validating the service descriptor ‘ServiceType:
Estato.Controllers.RoofTypeController Lifetime: Transient
ImplementationType: Estato.Controllers.RoofTypeController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.RoofTypeService’
while attempting to activate ‘Estato.Controllers.RoofTypeController’.)
(Error while validating the service descriptor ‘ServiceType:
Estato.Controllers.RoomController Lifetime: Transient
ImplementationType: Estato.Controllers.RoomController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.RoomService’ while
attempting to activate ‘Estato.Controllers.RoomController’.) (Error
while validating the service descriptor ‘ServiceType:
Estato.Controllers.SizeNameController Lifetime: Transient
ImplementationType: Estato.Controllers.SizeNameController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.SizeNameService’
while attempting to activate ‘Estato.Controllers.SizeNameController’.)
(Error while validating the service descriptor ‘ServiceType:
Estato.Controllers.ViewController Lifetime: Transient
ImplementationType: Estato.Controllers.ViewController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.ViewService’ while
attempting to activate ‘Estato.Controllers.ViewController’.) (Error
while validating the service descriptor ‘ServiceType:
Estato.Controllers.ZoneController Lifetime: Transient
ImplementationType: Estato.Controllers.ZoneController’: Unable to
resolve service for type ‘Estato.Core.BLL.Services.ZoneService’ while
attempting to activate ‘Estato.Controllers.ZoneController’.)

Note, I already tried to add builder.Services.AddScoped<Estato.Core.BLL.Services.ZoneService>();
also other services like ZoneService but I still have this error

2

Answers


  1. Chosen as BEST ANSWER

    I found a solution from this https://jinalkumarpatel.hashnode.dev/dependency-injection-in-net-with-autofac, thanks to all, here is part of my code to register services :

    builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
    builder.Host.ConfigureContainer<Autofac.ContainerBuilder>(autofacConfigure =>
    {
     autofacConfigure
           .RegisterType<ApplicationDbContext>()
                        .As<DbContext>()
                        .InstancePerLifetimeScope();
        autofacConfigure
            .RegisterGeneric(typeof(BaseRepository<>))
                        .As(typeof(BaseRepository<>))
                        .InstancePerLifetimeScope();
    ...
    }```
    

  2. There appears to be a number of services that are not registered that your Controllers are dependent upon.

    Taking the first error:

    (Error while validating the service descriptor ‘ServiceType:
    Estato.Controllers.AuthController Lifetime: Transient
    ImplementationType: Estato.Controllers.AuthController’: Unable to
    resolve service for type ‘Estato.Core.Security.IJwtFactory’ while
    attempting to activate ‘Estato.Controllers.AuthController’.)

    I don’t see IJwtFactory being registered anywhere. You’ll need to evaluate each exception in turn to ensure that all required services are registered.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search