AddDbContext 是单例模式的作用域,需要通过
using (var scope = _scopeFactory.CreateScope()) //剔除单例模式的Context问题。 { var wallContext = scope.ServiceProvider.GetRequiredService<WalletContext>(); var baseContext = scope.ServiceProvider.GetRequiredService<BaseContext>(); var MemberContext = scope.ServiceProvider.GetRequiredService<MemberContext>(); var orderContext = scope.ServiceProvider.GetRequiredService<OrderContext>(); var assetContext = scope.ServiceProvider.GetRequiredService<AssetContext>(); var consumeContext = scope.ServiceProvider.GetRequiredService<ConsumeDbContext>(); var itemdbContent = scope.ServiceProvider.GetRequiredService<ItemsDbContext>(); ....... }
来解决。
using (var scope = _scopeFactory.CreateScope()) //剔除单例模式的Context问题。 { var wallContext = scope.ServiceProvider.GetRequiredService<WalletContext>(); var baseContext = scope.ServiceProvider.GetRequiredService<BaseContext>(); var MemberContext = scope.ServiceProvider.GetRequiredService<MemberContext>(); var orderContext = scope.ServiceProvider.GetRequiredService<OrderContext>(); var assetContext = scope.ServiceProvider.GetRequiredService<AssetContext>(); var consumeContext = scope.ServiceProvider.GetRequiredService<ConsumeDbContext>(); var itemdbContent = scope.ServiceProvider.GetRequiredService<ItemsDbContext>();