小编Ste*_*eve的帖子

为什么数据库中的数据没有被更新但是对象却被更新并且没有错误?

我有这个银行ATM样机应用程序,它实现了一些域驱动的设计架构和工作单元模式。

这个程序有3个基本功能:

  • 查看余额
  • 存款
  • 退出

这些是项目层:

ATM.Model(域模型实体层)

namespace ATM.Model
{
public class BankAccount
{
    public int Id { get; set; }
    public string AccountName { get; set; }
    public decimal Balance { get; set; }

    public decimal CheckBalance()
    {
        return Balance;
    }

    public void Deposit(int amount)
    {
        // Domain logic
        Balance += amount;
    }

    public void Withdraw(int amount)
    {
        // Domain logic
        //if(amount > Balance)
        //{
        //    throw new Exception("Withdraw amount exceed account balance.");
        //}

        Balance -= amount;
    }
} …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework unit-of-work repository-pattern entity-framework-core

6
推荐指数
1
解决办法
300
查看次数

解析错误:由“<!DOCTYPE html>”引起的意外标记更漂亮/更漂亮

我有一个使用 vue cli 创建的 vue 应用程序,我使用的版本是 vue2(带有 eslint 和 prettier)。

我可以运行npm run serve并加载我的页面。但是在 Visual Studio Code 中,我注意到这个错误:

{
    "resource": "/c:/vue/app2/public/index.html",
    "owner": "eslint",
    "code": {
        "value": "prettier/prettier",
        "target": {
            "$mid": 1,
            "external": "https://github.com/prettier/eslint-plugin-prettier#options",
            "path": "/prettier/eslint-plugin-prettier",
            "scheme": "https",
            "authority": "github.com",
            "fragment": "options"
        }
    },
    "severity": 4,
    "message": "Parsing error: Unexpected token",
    "source": "eslint",
    "startLineNumber": 1,
    "startColumn": 2,
    "endLineNumber": 1,
    "endColumn": 2
}
Run Code Online (Sandbox Code Playgroud)

这是我.eslintrc.js创建应用程序时自动生成的,此后我没有对其进行任何更改。

module.exports = {  
  root: true,
  env: {
    node: true
  },
  extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
  parserOptions: …
Run Code Online (Sandbox Code Playgroud)

eslint prettier prettier-eslint

6
推荐指数
1
解决办法
2168
查看次数

如何使 fs.readFile 异步等待?

我这里有这个 NodeJS 代码,它读取文件夹并处理文件。该代码有效。但它仍然是先打印所有文件名,然后只读取文件。如何获取一个文件,然后先读取该文件的内容,而不是先获取所有文件?

async function readingDirectory(directory) {
    try {
        fileNames = await fs.readdir(directory);
        fileNames.map(file => {
            const absolutePath = path.resolve(folder, file);
            log(absolutePath);
            
            fs.readFile(absolutePath, (err, data) => {
                log(data); // How to make it async await here?                
            });
        });
    } catch {
        console.log('Directory Reading Error');
    }
}

readingDirectory(folder);
Run Code Online (Sandbox Code Playgroud)

node.js

6
推荐指数
1
解决办法
1万
查看次数

CsvHelper C# 日期时间格式 dd/mm/yyyy

我正在使用CsvHelper库将 CSV 数据解析为 C# 对象。到目前为止,我可以用这 3 列解析这个类的所有内容。

public class Foo
{
    public string Id { get; set; }
    public decimal Amount { get; set; }
    public string CurrencyCode { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

但在我添加 DateTime 属性后,它就崩溃了。添加新列后的类。

public class Foo
{
    public string Id { get; set; }
    public decimal Amount { get; set; }
    public string CurrencyCode { get; set; }
    public DateTime TransactionDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是我的配置

var config = new CsvConfiguration(CultureInfo.InvariantCulture)
            {
                HasHeaderRecord = …
Run Code Online (Sandbox Code Playgroud)

csvhelper

6
推荐指数
1
解决办法
8632
查看次数

如何使用 AspNetCore.HealthChecks.SqlServer 检查多个数据库?

目前我已经使用以下代码检查了一个数据库:

services.AddHealthChecks()
               .AddSqlServer(
                 connectionString: Configuration.GetConnectionString("DefaultConnection"),
                 healthQuery: "SELECT 1;",
                 name: "sql",
                 failureStatus: HealthStatus.Degraded,
                 tags: new string[] { "db", "sql", "sqlserver" }
               );
Run Code Online (Sandbox Code Playgroud)

但是如何检查多个数据库呢?我正在使用 .NET Core 3.1 和 AspNetCore.HealthChecks.SqlServer Version=3.1.1。

c# health-check

6
推荐指数
1
解决办法
2931
查看次数

重构许多重复的 ProducesResponseType 以使其干燥

目前,我有 20 个端点,它们的代码与这 3 行ProducesResponseType. 我正在使用 .NET Core 3.1 和 Swagger。如何重构我的代码以使其 DRY(不要重复自己)?

[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SuccessResponse))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ErrorResponse))]
[ProducesResponseType(StatusCodes.Status500InternalServerError, Type = typeof(ErrorResponse))]
public IActionResult Controller1(){
 // code removed for brevity
}

[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SuccessResponse))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ErrorResponse))]
[ProducesResponseType(StatusCodes.Status500InternalServerError, Type = typeof(ErrorResponse))]
public IActionResult Controller2(){
 // code removed for brevity
}

[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SuccessResponse))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ErrorResponse))]
[ProducesResponseType(StatusCodes.Status500InternalServerError, Type = typeof(ErrorResponse))]
public IActionResult Controller3(){
 // code removed for brevity
}
Run Code Online (Sandbox Code Playgroud)

c# swagger asp.net-core

5
推荐指数
1
解决办法
989
查看次数

postgresql pgadmin 永远加载

我曾多次尝试安装 postgresql+ pgadmin。我的环境是Window 10,postgresql版本是10.15(postgresql-10.15-1-windows-x64.exe)。安装完成,但是当我运行 pgadmin 时,它只是继续加载附件。

在此处输入图片说明

当我运行 powershell 时get-process,这就是我得到的: 在此处输入图片说明

我试图卸载它并在该过程中终止并重新安装,但我仍然遇到同样的问题。

windows-10 pgadmin-4

5
推荐指数
2
解决办法
4584
查看次数

如何在没有 FromBody 的情况下在邮递员中发布对象?

假设我的控制器正在接受一个没有[FromBody]的对象参数,我如何使用 Postman 发布数据?我试过这种方式,但它没有到达终点。

在此处输入图片说明

postman

5
推荐指数
1
解决办法
151
查看次数

Microsoft.AspNetCore.Authorization.DefaultAuthorizationService 授权失败。未满足这些要求:需要经过身份验证的用户

当我将 NET 6 blazor Web 应用程序(服务器和客户端)部署到 IIS 中时,但在运行它时出现此错误,http://blazorecommerceapi.findingsteve.net

Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
      Authorization failed. These requirements were not met:
      DenyAnonymousAuthorizationRequirement: Requires an authenticated user.
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

当我运行它的 api 时,http://blazorecommerceapi.findingsteve.net/api/product

在此输入图像描述

但当我在本地运行它时,它按预期工作。我可以运行 blazor 客户端页面。

在此输入图像描述

我可以看到api数据。

在此输入图像描述

我正在使用 Sqlite 来保存数据并进行身份验证,这些是 program.cs 中的一些代码

builder.Services.AddScoped<IAuthService, AuthService>();

builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuerSigningKey = true,
            IssuerSigningKey =
                new SymmetricSecurityKey(System.Text.Encoding.UTF8
                .GetBytes(builder.Configuration.GetSection("AppSettings:Token").Value)),
            ValidateIssuer = false,
            ValidateAudience = false
        };
    });

app.UseAuthentication();
app.UseAuthorization();
Run Code Online (Sandbox Code Playgroud)

c# blazor

5
推荐指数
1
解决办法
3631
查看次数

当我在 Visual Studio Pro 中按下 Docker 按钮时,实际运行的 Docker 命令是什么?

在此输入图像描述

假设我在使用 Visual Studio 创建项目时“启用 Docker”,然后按“Docker”图标,那么实际运行的 docker 命令是什么?

在此输入图像描述

visual-studio docker

5
推荐指数
1
解决办法
126
查看次数