public IAmbientDbContext Create(IDbContextFactory dbContextFactory, DbContextInstantiationStrategy joiningOption = DbContextInstantiationStrategy.AppendIfOneAlreadyInstantiated, IsolationLevel?isolationLevel = null) { if (joiningOption == DbContextInstantiationStrategy.CreateNewInstanceAnyway) { return(new AmbientDbContext(@readonly: false, isOrphan: true, isolationLevel: isolationLevel, dbContextFactory: dbContextFactory)); } var ambientDbContext = CallContext <IAmbientDbContext> .GetData(AmbientDbContextConstants.AmbientDbContextScopeKey); if (ambientDbContext != null) { ((AmbientDbContext)ambientDbContext).IncrementInstantiatedCount(); return(ambientDbContext); } ambientDbContext = new AmbientDbContext(false, isolationLevel, dbContextFactory); CallContext <IAmbientDbContext> .SetData(AmbientDbContextConstants.AmbientDbContextScopeKey, ambientDbContext); return(ambientDbContext); }
public ReadonlyAmbientDbContext(bool isOrphan, IsolationLevel?isolationLevel = null, IDbContextFactory dbContextFactory = null) { _internalScope = new AmbientDbContext(@readonly: true, isOrphan: isOrphan, isolationLevel: isolationLevel, dbContextFactory: dbContextFactory); }