public virtual IDatabaseProviderServices SelectServices(ServiceProviderSource providerSource)
        {
            var configured = _providers.Where(f => f.IsConfigured(_contextOptions)).ToArray();

            if (configured.Length == 1)
            {
                return(configured[0].GetProviderServices(_serviceProvider));
            }

            if (configured.Length > 1)
            {
                throw new InvalidOperationException(CoreStrings.MultipleProvidersConfigured(BuildDatabaseNamesString(configured)));
            }

            if (_providers.Length == 0)
            {
                if (providerSource == ServiceProviderSource.Implicit)
                {
                    throw new InvalidOperationException(CoreStrings.NoProviderConfigured);
                }
                throw new InvalidOperationException(CoreStrings.NoProviderServices);
            }

            if (_providers.Length > 1)
            {
                throw new InvalidOperationException(CoreStrings.MultipleProvidersAvailable(BuildDatabaseNamesString(_providers)));
            }

            throw new InvalidOperationException(CoreStrings.NoProviderConfigured);
        }
Пример #2
0
        public virtual DbContextConfiguration Initialize(
            [NotNull] IServiceProvider externalProvider,
            [NotNull] IServiceProvider scopedProvider,
            [NotNull] DbContextOptions contextOptions,
            [NotNull] DbContext context,
            ServiceProviderSource serviceProviderSource)
        {
            Check.NotNull(externalProvider, "externalProvider");
            Check.NotNull(scopedProvider, "scopedProvider");
            Check.NotNull(contextOptions, "contextOptions");
            Check.NotNull(context, "context");
            Check.IsDefined(serviceProviderSource, "serviceProviderSource");

            _externalProvider      = externalProvider;
            _services              = new ContextServices(scopedProvider);
            _serviceProviderSource = serviceProviderSource;
            _contextOptions        = contextOptions;
            _context           = context;
            _dataStoreServices = new LazyRef <DataStoreServices>(() => _services.DataStoreSelector.SelectDataStore(this));
            _modelFromSource   = new LazyRef <IModel>(() => _services.ModelSource.GetModel(_context, _dataStoreServices.Value.ModelBuilderFactory));
            _dataStore         = new LazyRef <DataStore>(() => _dataStoreServices.Value.Store);
            _connection        = new LazyRef <DataStoreConnection>(() => _dataStoreServices.Value.Connection);
            _loggerFactory     = new LazyRef <ILoggerFactory>(() => _externalProvider.TryGetService <ILoggerFactory>() ?? new NullLoggerFactory());
            _database          = new LazyRef <Database>(() => _dataStoreServices.Value.Database);
            _stateManager      = new LazyRef <StateManager>(() => _services.StateManager);

            return(this);
        }
        public virtual IDataStoreServices SelectDataStore(ServiceProviderSource providerSource)
        {
            Check.IsDefined(providerSource, nameof(providerSource));

            var configured = _sources.Where(f => f.IsConfigured(_contextOptions)).ToArray();

            if (configured.Length == 1)
            {
                return configured[0].GetStoreServices(_serviceProvider);
            }

            if (configured.Length > 1)
            {
                throw new InvalidOperationException(Strings.MultipleDataStoresConfigured(BuildStoreNamesString(configured)));
            }

            if (_sources.Length == 0)
            {
                if (providerSource == ServiceProviderSource.Implicit)
                {
                    throw new InvalidOperationException(Strings.NoDataStoreConfigured);
                }
                throw new InvalidOperationException(Strings.NoDataStoreService);
            }

            if (_sources.Length > 1)
            {
                throw new InvalidOperationException(Strings.MultipleDataStoresAvailable(BuildStoreNamesString(_sources)));
            }

            throw new InvalidOperationException(Strings.NoDataStoreConfigured);
        }
        public virtual IDataStoreServices SelectDataStore(ServiceProviderSource providerSource)
        {
            Check.IsDefined(providerSource, nameof(providerSource));

            var configured = _sources.Where(f => f.IsConfigured(_contextOptions)).ToArray();

            if (configured.Length == 1)
            {
                return(configured[0].GetStoreServices(_serviceProvider));
            }

            if (configured.Length > 1)
            {
                throw new InvalidOperationException(Strings.MultipleDataStoresConfigured(BuildStoreNamesString(configured)));
            }

            if (_sources.Length == 0)
            {
                if (providerSource == ServiceProviderSource.Implicit)
                {
                    throw new InvalidOperationException(Strings.NoDataStoreConfigured);
                }
                throw new InvalidOperationException(Strings.NoDataStoreService);
            }

            if (_sources.Length > 1)
            {
                throw new InvalidOperationException(Strings.MultipleDataStoresAvailable(BuildStoreNamesString(_sources)));
            }

            throw new InvalidOperationException(Strings.NoDataStoreConfigured);
        }
        public virtual IDatabaseProviderServices SelectServices(ServiceProviderSource providerSource)
        {
            var configured = _providers.Where(f => f.IsConfigured(_contextOptions)).ToArray();

            if (configured.Length == 1)
            {
                return configured[0].GetProviderServices(_serviceProvider);
            }

            if (configured.Length > 1)
            {
                throw new InvalidOperationException(CoreStrings.MultipleProvidersConfigured(BuildDatabaseNamesString(configured)));
            }

            if (_providers.Length == 0)
            {
                if (providerSource == ServiceProviderSource.Implicit)
                {
                    throw new InvalidOperationException(CoreStrings.NoProviderConfigured);
                }
                throw new InvalidOperationException(CoreStrings.NoProviderServices);
            }

            if (_providers.Length > 1)
            {
                throw new InvalidOperationException(CoreStrings.MultipleProvidersAvailable(BuildDatabaseNamesString(_providers)));
            }

            throw new InvalidOperationException(CoreStrings.NoProviderConfigured);
        }
        public virtual DbContextConfiguration Initialize(
            [NotNull] IServiceProvider externalProvider,
            [NotNull] IServiceProvider scopedProvider,
            [NotNull] DbContextOptions contextOptions,
            [NotNull] DbContext context,
            ServiceProviderSource serviceProviderSource)
        {
            Check.NotNull(externalProvider, "externalProvider");
            Check.NotNull(scopedProvider, "scopedProvider");
            Check.NotNull(contextOptions, "contextOptions");
            Check.NotNull(context, "context");
            Check.IsDefined(serviceProviderSource, "serviceProviderSource");

            _externalProvider = externalProvider;
            _services = new ContextServices(scopedProvider);
            _serviceProviderSource = serviceProviderSource;
            _contextOptions = contextOptions;
            _context = context;
            _dataStoreServices = new LazyRef<DataStoreServices>(() => _services.DataStoreSelector.SelectDataStore(this));
            _modelFromSource = new LazyRef<IModel>(() => _services.ModelSource.GetModel(_context, _dataStoreServices.Value.ModelBuilderFactory));
            _dataStore = new LazyRef<DataStore>(() => _dataStoreServices.Value.Store);
            _connection = new LazyRef<DataStoreConnection>(() => _dataStoreServices.Value.Connection);
            _loggerFactory = new LazyRef<ILoggerFactory>(() => _externalProvider.TryGetService<ILoggerFactory>() ?? new NullLoggerFactory());
            _database = new LazyRef<Database>(() => _dataStoreServices.Value.Database);
            _stateManager = new LazyRef<StateManager>(() => _services.StateManager);

            return this;
        }
        public virtual IDbContextServices Initialize(
            IServiceProvider scopedProvider,
            IDbContextOptions contextOptions,
            DbContext context,
            ServiceProviderSource serviceProviderSource)
        {
            Check.NotNull(scopedProvider, nameof(scopedProvider));
            Check.NotNull(contextOptions, nameof(contextOptions));
            Check.NotNull(context, nameof(context));

            _provider       = scopedProvider;
            _contextOptions = contextOptions;
            _context        = context;

            _providerServices = new LazyRef <IDatabaseProviderServices>(() =>
                                                                        _provider.GetRequiredService <IDatabaseProviderSelector>().SelectServices(serviceProviderSource));

            _modelFromSource = new LazyRef <IModel>(CreateModel);

            return(this);
        }
        public virtual DbContextServices Initialize(
            [NotNull] IServiceProvider scopedProvider,
            [NotNull] DbContextOptions contextOptions,
            [NotNull] DbContext context,
            ServiceProviderSource serviceProviderSource)
        {
            Check.NotNull(scopedProvider, "scopedProvider");
            Check.NotNull(contextOptions, "contextOptions");
            Check.NotNull(context, "context");
            Check.IsDefined(serviceProviderSource, "serviceProviderSource");

            _scopedProvider = scopedProvider;
            _contextOptions = contextOptions;
            _context        = context;

            _dataStoreServices = new LazyRef <DataStoreServices>(() =>
                                                                 _scopedProvider.GetRequiredServiceChecked <DataStoreSelector>().SelectDataStore(serviceProviderSource));

            _modelFromSource = new LazyRef <IModel>(CreateModel);

            return(this);
        }
Пример #9
0
        public virtual IDbContextServices Initialize(
            IServiceProvider scopedProvider, 
            IDbContextOptions contextOptions, 
            DbContext context,
            ServiceProviderSource serviceProviderSource)
        {
            Check.NotNull(scopedProvider, nameof(scopedProvider));
            Check.NotNull(contextOptions, nameof(contextOptions));
            Check.NotNull(context, nameof(context));
            Check.IsDefined(serviceProviderSource, nameof(serviceProviderSource));

            _provider = scopedProvider;
            _contextOptions = contextOptions;
            _context = context;

            _dataStoreServices = new LazyRef<IDataStoreServices>(() =>
                _provider.GetRequiredService<IDataStoreSelector>().SelectDataStore(serviceProviderSource));

            _modelFromSource = new LazyRef<IModel>(CreateModel);

            return this;
        }