Preventing Concurrency Issues – Repository Pattern

Hi

I have a .Net Core Blazor server project and I'm making use of the Repository pattern for data access. Initially, I had registered the repository as a scoped service.

While testing I noticed that if I quickly switched pages for e.g. by clicking on the navigation menu, while the repository is being used on the current page, the application would throw an exception related to the DbContext being accessed concurrently.

What's the best way to prevent an issue like this from occurring, besides registering the repository as a transient service, which would mean multiple DbContext instances, I'm currently using this approach as a patch.

Thanks in advance!