在我的 ASP.NET Core-6 Web API 中,当我尝试安装时:
安装包 AutoMapper.Extensions.Microsoft.DependencyInjection -版本 11.0.0
通过 Nugget 包,我收到此错误:
检测到的软件包版本超出依赖性约束:Duende.IdentityServer.EntityFramework.Storage 5.2.0 需要 AutoMapper (>= 10.0.0 && < 11.0.0),但版本 AutoMapper 11.0.1 已解决。
在尝试解决它时,我安装了 AutoMapper ver-11.0.1
然后应用程序标记已安装的 AutoMapper。
我该如何解决这个问题?
谢谢
在 ASP.NET Core-6 Web API 中,我在 WebApi 项目的 Program.cs 中有以下代码:
WebApi程序.cs:
var builder = WebApplication.CreateBuilder(args);
// 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();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
错误 CS0103 当前上下文 WebApi 中不存在名称“WebApplication”
我该如何解决这个问题?
谢谢
在我的 ASP.NET Core-6 Web API 中,我安装了 Serilog。我从未安装过 Microsoft.Extensions.Logging
但令我惊讶的是,当我想使用以下方式引用 Serilog 时:
using ILogger = Serilog.ILogger;
public class AuthController : BaseApiController
{
private readonly ILogger<AuthController> _logger;
private IAuthService _authService;
public AuthController(ILogger<AuthController> logger, IAuthService authService)
{
_logger = logger;
_authService = authService;
}
}
Run Code Online (Sandbox Code Playgroud)
ILogger自动检测Microsoft.Extensions.Logging,我无法更改为Serilog。
我该如何解决这个问题?
谢谢
在 Angular-14 项目中,我有这个package.json:
包.json:
"dependencies": {
"@angular/animations": "^14.0.0",
"@angular/common": "^14.0.0",
"@angular/compiler": "^14.0.0",
"@angular/core": "^14.0.0",
"@angular/forms": "^14.0.0",
"@angular/platform-browser": "^14.0.0",
"@angular/platform-browser-dynamic": "^14.0.0",
"@angular/router": "^14.0.0",
"@rxweb/reactive-form-validators": "^2.1.7",
"admin-lte": "3.2",
"google-libphonenumber": "^3.2.28",
"intl-tel-input": "^17.0.3",
"ngx-toastr": "^14.3.0",
"npm-check": "^5.9.2",
"rxjs": "~7.5.0",
"sweetalert2": "^11.4.17",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
Run Code Online (Sandbox Code Playgroud)
ngx-bootstrap因此,当我决定使用ngx bootstrap安装时:
npm 安装 ngx-bootstrap --save
我收到这个错误:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: ddm-ui@0.0.0
npm ERR! Found: @angular/animations@14.0.1
npm ERR! …Run Code Online (Sandbox Code Playgroud) 我正在 ASP.NET Core-6 Web API 用户身份验证登录中实现 CurrentUser 服务。我正在使用 IdentityDbContext:
当前用户服务:
public interface ICurrentUserService
{
public string UserId { get; }
public string UserName { get; }
bool IsAuthenticated { get; }
public string IpAddress { get; }
}
Run Code Online (Sandbox Code Playgroud)
当前用户服务:
using Microsoft.AspNetCore.Http;
using System.Security.Claims;
public class CurrentUserService : ICurrentUserService
{
public string UserId { get; }
public string UserName { get; }
public bool IsAuthenticated { get; }
public string IpAddress { get; }
public CurrentUserService(IHttpContextAccessor httpContextAccessor)
{
IpAddress = httpContextAccessor.HttpContext?.Connection?.RemoteIpAddress.ToString(); …Run Code Online (Sandbox Code Playgroud) 在我使用实体框架的 ASP.NET Core-6 Web API 中,我有以下代码:
我正在使用 IdentityDbContext。
应用程序数据库上下文:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
public DbSet<ApplicationRole> ApplicationRoles { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
builder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly);
base.OnModelCreating(builder);
}
}
Run Code Online (Sandbox Code Playgroud)
连接配置:
public static class ConnectionConfiguration
{
public static void AddDbContextAndConfigurations(this IServiceCollection services, IWebHostEnvironment env, IConfiguration config)
{
services.AddDbContextPool<ApplicationDbContext>(options =>
{
string connStr;
connStr = config.GetConnectionString("MssqlDbConnection");
options.UseSqlServer(connStr);
});
}
}
Run Code Online (Sandbox Code Playgroud)
程序.cs:
var builder = WebApplication.CreateBuilder(args); …Run Code Online (Sandbox Code Playgroud) 在 ASP.NET Core-6 Web API 中,我使用 FluentValidation.AspNetCore(11.2.1)。
我在 Program.cs 中有这段代码:
builder.Services.AddMvc().AddFluentValidation(fv => {
fv.DisableDataAnnotationsValidation = true;
fv.RegisterValidatorsFromAssembly(typeof(Program).Assembly);
fv.RegisterValidatorsFromAssembly(Assembly.GetExecutingAssembly());
fv.ImplicitlyValidateChildProperties = true;
fv.ImplicitlyValidateRootCollectionElements = true;
fv.AutomaticValidationEnabled = true;
});
Run Code Online (Sandbox Code Playgroud)
但我得到了这个错误,上面的所有代码都突出显示:
FluentValidationMvcExtensions.AddFluentValidation(IMvcBuilder, Action)' 已过时:'不推荐调用 AddFluentValidation()
我该如何解决这个问题?
谢谢