Where() after repostory GetAll(), shows DbContext has been disposed

388 Views Asked by At

Exceptions Screenshot:

Exceptions Screenshot

ABP Official Test Case: ABP Official Test Case

Actually, I am studying the ABP source code for building a new project using the unit of work module of ABP.

I wonder why this shows "the DbContext has been disposed", because In ABP, repository is defined as UOW.

An other situation is that, if I manually set a UOW class, the call will be ok as below.

Configuration.UnitOfWork.ConventionalUowSelectors.Add(type => type == typeof(MyCustomUowClass));

ABP framework was helped me I lot, once I began to work on the road of solution architecture.

It's important for me to figure out How this won't work.

Thanks for reading.


It's not a simple question, i know it should be disposed after using it.

but i don't know where to disposed, because it relate to the UOW of ABP methodology. I may missed something in somewhere.

3

There are 3 best solutions below

0
On BEST ANSWER

Try moving the faulting code to inside the using block. Exiting using block means the variable has been disposed off and can't used anymore.

0
On

The issue is coming from you have disposed of the users variable in your using statement.

The reason is the users is resolved out of the context which is resolved from your IocManager (which I am assuming disposes of the scope and all the scopes resources). Therefore you are getting the disposed error message.

Your using block should encapsulate all the objects that are referencing the context scope (ie users)

0
On

You can only make database operations in SimpleDbContext using block.

enter image description here