public DataContextSupervisor(Func<ReadOnlyDictionary<string, DataSource>> dataSourcesProvider,
            ITerminationPolicy terminationPolicy = null)
        {
            if (dataSourcesProvider == null) throw new ArgumentNullException("dataSourcesProvider");

            this.dataSourcesProvider = dataSourcesProvider;
            this.terminationPolicy = terminationPolicy ?? new ImmediateTerminationPolicy();
        }
Exemple #2
0
        public DataContext([NotNull] UnitOfWorkConfig configuration, [NotNull] Lazy<IDataSession> session, [NotNull] ITerminationPolicy terminationPolicy)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            if (terminationPolicy == null)
            {
                throw new ArgumentNullException("terminationPolicy");
            }

            this.configuration = configuration;
            this.session = session;
            this.terminationPolicy = terminationPolicy;
            extra = new ExpandoObject();

            ((dynamic)extra).Extensions = new Dictionary<string, object>();
        }
 public OperationScope(ITerminationPolicy terminationPolicy = null)
 {
     this.terminationPolicy = terminationPolicy ?? new DeferredTerminationPolicy();
     InternalEnvironment.RegisterOperationScope(this.terminationPolicy);
 }
        internal static void RegisterOperationScope(ITerminationPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException("policy");
            }

            if (LogicContext.FindData(OperationScopeKey) != null)
            {
                throw new Exception("Operation scope does not support nesting.");
            }

            if (LogicContext.FindData(DataContextSupervisorKey) != null)
            {
                throw new Exception("Operation scope can not be used inside of unit of work.");
            }

            LogicContext.SetData(OperationScopeKey, new object());

            var supervisor = new DataContextSupervisor(() => new ReadOnlyDictionary<string, DataSource>(dataSources), policy);

            LogicContext.SetData(DataContextSupervisorKey, supervisor);
        }