internal IServiceScopeFactory Initialize(KSqlDBContextOptions contextOptions)
        {
            if (!wasConfigured)
            {
                wasConfigured = true;

                RegisterDependencies(contextOptions);

                ServiceProvider = serviceCollection.BuildServiceProvider(new ServiceProviderOptions {
                    ValidateScopes = true
                });
            }

            var serviceScopeFactory = ServiceProvider.GetService <IServiceScopeFactory>();

            return(serviceScopeFactory);
        }
        protected virtual void OnConfigureServices(IServiceCollection serviceCollection, KSqlDBContextOptions contextOptions)
        {
            serviceCollection.TryAddScoped <IKSqlQbservableProvider, QbservableProvider>();
            serviceCollection.TryAddScoped <ICreateStatementProvider, CreateStatementProvider>();

            var uri = new Uri(contextOptions.Url);

            serviceCollection.TryAddTransient <IKSqlQueryGenerator, KSqlQueryGenerator>();

            if (!serviceCollection.HasRegistration <IHttpClientFactory>())
            {
                serviceCollection.AddSingleton <IHttpClientFactory, HttpClientFactory>(_ =>
                                                                                       new HttpClientFactory(uri));
            }

            serviceCollection.TryAddSingleton(contextOptions);
            serviceCollection.TryAddScoped <IKStreamSetDependencies, KStreamSetDependencies>();
            serviceCollection.TryAddScoped <IKSqlDbRestApiClient, KSqlDbRestApiClient>();
        }
 private void RegisterDependencies(KSqlDBContextOptions contextOptions)
 {
     OnConfigureServices(serviceCollection, contextOptions);
 }
Exemple #4
0
        public KSqlDBContext(KSqlDBContextOptions contextOptions)
        {
            this.contextOptions = contextOptions ?? throw new ArgumentNullException(nameof(contextOptions));

            serviceCollection = new ServiceCollection();
        }
Exemple #5
0
        protected override void OnConfigureServices(IServiceCollection serviceCollection, KSqlDBContextOptions contextOptions)
        {
            base.OnConfigureServices(serviceCollection, contextOptions);

            serviceCollection.TryAddScoped <IKSqlDbProvider, KSqlDbQueryProvider>();
            serviceCollection.TryAddSingleton(contextOptions.QueryParameters);
        }
Exemple #6
0
 public KSqlDBContext(KSqlDBContextOptions contextOptions)
 {
     this.contextOptions = contextOptions ?? throw new ArgumentNullException(nameof(contextOptions));
 }