I have an Xamarin Forms app with prism Dryioc 7.1, and I had landed on the following problem: A second operation started on this context before a previous operation completed.
So i followed this post #https://www.pmichaels.net/tag/a-second-operation-started-on-this-context-before-a-previous-operation-completed/
That fixed my problem until I added tabbed pages on the XF app, because all tabbed pages initialize at the same time, I'm having concurrent Services classes accessing my DBContext, on which I had assumption they were different instances, at least when they are created they have a different GUID, however seems that every time my DBContext is disposed, dispose all instances of DBContext, I created a simple tabbed page app in XF with Prism that replicates my problem, when I use my DBContext on Web Server I create scopes, however with prism I can't seem able to do, because if I try to inject IContainerRegistry and IContainerProvider on my Service Class just doesn't work my app.
I have looked everywhere and I can't find a way to create a scope on the service page
My IGenerateDbContext Inteface only have one method
public IApplicationDbContext GenerateNewContext()
{
IApplicationDbContext dbContext = new ApplicationDbContext(_sqlite);
return dbContext;
}
My Data Store accessing the DbContext through IGenerateDbContext
using (IApplicationDbContext myDbContext = _generateDbContext.GenerateNewContext())
{
....
removed for simplicity
}
Full app available here https://github.com/silvajnr/PrismTabbedDbContext
I read that prism creates a DBContext per ViewModel, should just synchronise the DBConetx with Mutex locks
Error: System.ObjectDisposedException: Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances. Object name: 'ApplicationDbContext'.