Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to call var scope = ScopeFactory.CreateScope(); and still have one depency resolved from rootProvider

$
0
0

I have situation like this: I have two Blazor components, both using dbContext and I get popular error

A second operation was started on this context instance before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext

I want to use OwningComponentBase which actually just does ScopeFactory.CreateScope() and in theory that should work because new it will use new instance of dbContext.

However, now that creates another problem. My MyService class has a dependency on MyDbContext, but also on MyAuthState and now MyAuthState is lost since it is not resolved from rootProvider but this is new instance:

class MyService(MyDbContext ctx, MyAuthState myAuthState){}

I noticed there is no public API to create all the scoped services except this one.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>