Serdan
Serdan

Reputation: 21

NServiceBus & Entity Framework

I am working on a project that uses NServiceBus ESB. A microservice "A" send a request to microservice "B" asking for a list of data records (e.g. instructor records) stored in the database. Is there a way in which inside the Handle method we could do some thing like:

 List<Instructor> instructors = await _coursecontext.CourseSet
     .Where(x => x.InstructorGuid == instructor.Instructor_Unique_Id)
     .ToListAsync();

currently I get the error message that the Handle method must be made async.

Thanks!

I changed the Handle to be async but then ran into problems that Handle is not implemented correctly:

async Task Handle(Command myrequest, IMessageHandlerContext context)

Upvotes: 2

Views: 81

Answers (1)

Guru Stron
Guru Stron

Reputation: 141565

NServiceBus handlers support task-based asynchrony, just add the async keyword (which enables the use of await) to the implementation :

public class MyAsyncHandler : IHandleMessages<MyMessage>
{
    public async Task Handle(MyMessage message, IMessageHandlerContext context)
    {
        // do something with the message data
    }
}

See also:

Upvotes: 0

Related Questions