我有这个银行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
我有一个使用 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) 我这里有这个 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) 我正在使用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) 目前我已经使用以下代码检查了一个数据库:
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。
目前,我有 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) 当我将 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# ×4
asp.net-core ×1
blazor ×1
csvhelper ×1
docker ×1
eslint ×1
health-check ×1
node.js ×1
pgadmin-4 ×1
postman ×1
prettier ×1
swagger ×1
unit-of-work ×1
windows-10 ×1