ABP System.ObjectDisposedException: Cannot access a disposed object.

错误:

 End of inner exception stack trace --- [See nested exception: System.ObjectDisposedException: 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: 'EMSDbContext'.

场景:

在job中直接调用Manager中的方法,进入方法后每次调用数据库的查询等方法都会提示上下文被释放掉了,但单独调用Insert方法不会保存

解决方法:

多方对比测试,发现job通过AppService去调用Manager中的方法,就不会报错。

猜测原因,大概是ABP在AppService中对上下文做了相应的处理。

原文地址:https://www.cnblogs.com/sugarwxx/p/14738484.html