Base solution for your next web application
Open Closed

ObjectDisposedException in Worker but not in AppService #4040


User avatar
0
lgarcia created

Hello, I have this code working fine in an ApplicationService but the same code in a Worker is throwing ObjectDisposedException.

var query = _repository.Query(x => x.OfType<MyChildEntity>());
var result = await query.FirstOrDefaultAsync();

Is there something that I'm doing wrong? Thanks in advance.


2 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    You need to be in an UnitOfWork when you call .FirstOrDefaultAsync(). You can first try the [UnitOfWork] attribute on a public virtual function. If that does not work, you need to inject and use IUnitOfWorkManager.

  • User Avatar
    0
    lgarcia created

    <cite>aaron: </cite> You need to be in an UnitOfWork when you call .FirstOrDefaultAsync(). You can first try the [UnitOfWork] attribute on a public virtual function. If that does not work, you need to inject and use IUnitOfWorkManager.

    Thank you for your quick respone, It worked with the [UnitOfWork] attribute :D.