DbContext Use WebApi will auto dispose
目前在使用MongoDb時,
如果出現Exception,
下次Request進來再使用此MongoDb,
會出現下列錯誤
1 | 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. |
可能的解決辦法
Entity Framework’s DBContext Disposal in Web Api Async
EntityFrameworkCore MongoDb Provider Data欄位每筆資料需相同
如果A資料有 ID NAME DES,
B資料有 ID NAME DES OTHER,
則會因為無法DeSerialize而Fail。