0%

紀錄一下說不定以後用的到的讀Configuration

1
2
3
4
5
6
7
8
9
var configuration = builder.Build();

Console.WriteLine("--------------------------");
var section = configuration.GetSection("Mission_EnemyData").GetChildren().Where(x => x.GetSection("Mission_ID").Value == "Mission_002");
foreach (var s in section)
{
Console.WriteLine($"Key: {s.Key,-30} || Value: {s.Value} || Path: {s.Path}");
}
Console.WriteLine("--------------------------");

在MongoDB用Set加入一個新Field在Document內

StackOverflow : How to add new fields to existing document

MongoDB C# Drive 使用方法

MongoDB Driver Quick Tour

C#算時間差距

StackOverflow : Showing Difference between two datetime values in hours

RoleManager要先有Role才能新增AddToRoleAsync()

StackOverflow : userManager.AddToRoleAsync() - Error: role does not exist

1
2
3
4
5
6
7
8
// Add the Admin role to the database
IdentityResult roleResult;
bool adminRoleExists = await _roleManager.RoleExistsAsync("Admin");
if (!adminRoleExists)
{
_logger.LogInformation("Adding Admin role");
roleResult = await _roleManager.CreateAsync(new IdentityRole("Admin"));
}

C# One Line If-Else

每次都忘記
return (expression) ? value1 : value2;

C# Compiler Error : Inconsistent accessibility: parameter type is less accessible

原因是public的class內用到了inter的interface
安捏母湯

C#函数编译出错:Inconsistent accessibility: parameter type ‘aaa.bbb.ccc’ is less accessible than method ‘aaa.bbb.functionName(aaa.bbb.ccc)

C# Check Object is null

很簡單
if(data != null)

StackOverflow : Checking if an object is null in C#

DbContext Use WebApi will auto dispose

目前在使用MongoDb時,
如果出現Exception,
下次Request進來再使用此MongoDb,
會出現下列錯誤

1
2
Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: 'DbContext'.

可能的解決辦法
Entity Framework’s DBContext Disposal in Web Api Async

EntityFrameworkCore MongoDb Provider Data欄位每筆資料需相同

如果A資料有 ID NAME DES,
B資料有 ID NAME DES OTHER,
則會因為無法DeSerialize而Fail。

Controller, Service, Repository

之前太拘泥於一個Controller就要對單一的Service,
和一個Service要對單一的Repository,
導致我的邏輯很難寫。

Controller應該根據要用哪個服務決定使用哪個Service,
再由Service處理商業邏輯。

4種Repository常見的錯誤

4 Common Mistakes with the Repository Pattern

別在Repository內做save,
不然有可能造成資料不統一,
目前我的架構有這個問題,
隱性的程式債R,未來要修。

今天是父親節呢

第一次父親節沒在家裡過呢
有種出來打拼的游子的感覺
父親節快樂R My Father

使用MongoDB有時候DbContext會Dispose的問題

Cannot access a disposed object in ASP.NET Core when injecting DbContext

我的原因大部分是async的關係,
將async改成同步方式就沒問題了。

使用Swagger in Asp.Net Core

我是使用 Swashbuckle 這個
Github : Swashbuckle.AspNetCore

MicrosoftDoc : Get started with Swashbuckle and ASP.NET Core

搭配 John wu 的 blog 的中文解說可以很容易理解

[鐵人賽 Day13] ASP.NET Core 2 系列 - Web API 文件產生器 (Swagger)

使用 SwaggerUI & SwaggerHub 來發布
SwaggerHub

似乎有可以先寫 swagger文件然後 generate code 的東西,不過還沒研究就是
Github : swagger-codegen

無標的日常

昨天是八月的第一天
加班到九點半還忙到忘記寫日誌了
重構的差不多了
現在要把找BUG讓測試CODE都能跑
就醬
沒啥時間LA
Q_Q

Refactoring ing ing ing ing ing

無止盡的重構日

重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構重構

好累

The most most most most most most most most

標題無意義

想想今天要做什麼

  1. 剪頭毛
  2. 去大潤發買生活必需用品
  3. 刷LeetCode三題好了
  4. 看ㄍ書

大致是醬