I have a Blazor project (Webassembly)
I want to start the application and it ends with an error message in program.cs on line: var app = builder.Build();
using myWebapp.Blazor.Server.Data;
using myWebapp.Blazor.Server.Models;
using myWebappData;
using myWebappService.Configuration;
using myWebappService.Services;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
//var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
//builder.Services.AddDbContext<ApplicationDbContext>(options =>
// options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDbContext<efmDbContext>(options =>
options.UseSqlServer(
connectionString: builder.Configuration.GetConnectionString("DefaultConnection")));
//RegisterDependencyServiceServiceLayer.ConfigureService(builder.Services);
builder.Services.AddTransient<IMyIndexService, MyIndexService>();
builder.Services.AddTransient<IMyViewsService, MyViewsService>();
builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
builder.Services.AddAuthentication()
.AddIdentityServerJwt();
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
app.UseWebAssemblyDebugging();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseIdentityServer();
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();
app.MapControllers();
app.MapFallbackToFile("index.html");
app.Run();
This is included:
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.8" />
This is the message:
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: myWebappService.Services.IMyIndexService Lifetime: Transient ImplementationType: myWebappService.Services.MyIndexService': Unable to resolve service for type 'AutoMapper.IMapper' while attempting to activate 'myWebappService.Services.MyIndexService'.) (Error while validating the service descriptor 'ServiceType: myWebappService.Services.IMyViewsService Lifetime: Transient ImplementationType: myWebappService.Services.MyViewsService': Unable to resolve service for type 'AutoMapper.IMapper' while attempting to activate 'myWebappService.Services.MyViewsService'.)'
InvalidOperationException: Unable to resolve service for type 'AutoMapper.IMapper' while attempting to activate 'myWebappService.Services.MyIndexService'.