/// <summary>
 /// Adds an EFCore based multitenant store to the application. Will also add the database context service unless it is already added.
 /// </summary>
 /// <returns>The same MultiTenantBuilder passed into the method.</returns>
 public static FinbuckleMultiTenantBuilder WithEFCoreStore <TEFCoreStoreDbContext, TTenantInfo>(this FinbuckleMultiTenantBuilder builder)
     where TEFCoreStoreDbContext : EFCoreStoreDbContext <TTenantInfo>
     where TTenantInfo : class, IEFCoreStoreTenantInfo, new()
 {
     builder.Services.AddDbContext <TEFCoreStoreDbContext>(); // Note, will not override existing context if already added.
     return(builder.WithStore <EFCoreStore <TEFCoreStoreDbContext, TTenantInfo> >(ServiceLifetime.Scoped));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Adds an Entity Framework store using the <see cref="DefaultTenantDbContext"/> and caches tenants for a configurable period of time.
 /// </summary>
 /// <returns>The same MultiTenantBuilder passed into the method.</returns>
 public static FinbuckleMultiTenantBuilder WithDefaultEFCacheStore(this FinbuckleMultiTenantBuilder builder, int cacheMinutes, Action <DbContextOptionsBuilder> options)
 {
     builder.Services.AddSingleton <ITenantConfiguration>(new TenantConfiguration()
     {
         Key = Constants.CacheMinutes, Value = cacheMinutes
     });
     builder.Services.AddTenantConfigurations();
     builder.Services.AddDbContext <DefaultTenantDbContext>(options); // Note, will not override existing context if already added.
     return(builder.WithStore <DefaultEFCacheStore>(ServiceLifetime.Scoped));
 }
        /// <summary>
        /// Adds and configures InMemoryStore to the application using the provided action.
        /// </summary>
        /// <param name="config">A delegate or lambda for configuring the tenant.</param>
        /// <param name="ignoreCase">Whether the store should ignore case.</param>
        /// <returns>The same MultiTenantBuilder passed into the method.</returns>
        public static FinbuckleMultiTenantBuilder WithInMemoryStore(this FinbuckleMultiTenantBuilder builder,
                                                                    Action <InMemoryStoreOptions> config,
                                                                    bool ignoreCase)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            return(builder.WithStore <InMemoryStore>(ServiceLifetime.Singleton, sp => InMemoryStoreFactory(config, ignoreCase)));
        }
        /// <summary>
        /// Adds a HttpRemoteStore to the application.
        /// </summary>
        /// <param name="builder">The builder instance.</param>
        /// <param name="endpointTemplate">The endpoint URI template.</param>
        /// <param name="clientConfig">An action to configure the underlying HttpClient.</param>
        public static FinbuckleMultiTenantBuilder <TTenantInfo> WithHttpRemoteStore <TTenantInfo>(this FinbuckleMultiTenantBuilder <TTenantInfo> builder,
                                                                                                  string endpointTemplate,
                                                                                                  Action <IHttpClientBuilder>?clientConfig) where TTenantInfo : class, ITenantInfo, new()
        {
            var httpClientBuilder = builder.Services.AddHttpClient(typeof(HttpRemoteStoreClient <TTenantInfo>).FullName !);

            clientConfig?.Invoke(httpClientBuilder);

            builder.Services.TryAddSingleton <HttpRemoteStoreClient <TTenantInfo> >();

            return(builder.WithStore <HttpRemoteStore <TTenantInfo> >(ServiceLifetime.Singleton, endpointTemplate));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds and configures InMemoryStore to the application using the provided action.
        /// </summary>
        /// <param name="config">A action for configuring the store.</param>
        /// <param name="ignoreCase">Whether the store should ignore case.</param>
        public static FinbuckleMultiTenantBuilder <TTenantInfo> WithInMemoryStore <TTenantInfo>(this FinbuckleMultiTenantBuilder <TTenantInfo> builder,
                                                                                                Action <InMemoryStoreOptions <TTenantInfo> > config)
            where TTenantInfo : class, ITenantInfo, new()
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            builder.Services.Configure <InMemoryStoreOptions <TTenantInfo> >(config);

            return(builder.WithStore <InMemoryStore <TTenantInfo> >(ServiceLifetime.Singleton));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds a HttpRemoteSTore to the application.
        /// </summary>
        /// <param name="endpointTemplate">The endpoint URI template.</param>
        /// <param name="clientConfig">An action to configure the underlying HttpClient.</param>
        public static FinbuckleMultiTenantBuilder WithHttpRemoteStore(this FinbuckleMultiTenantBuilder builder,
                                                                      string endpointTemplate,
                                                                      Action <IHttpClientBuilder> clientConfig)
        {
            var httpClientBuilder = builder.Services.AddHttpClient(typeof(HttpRemoteStoreClient).FullName);

            if (clientConfig != null)
            {
                clientConfig(httpClientBuilder);
            }

            builder.Services.TryAddSingleton <HttpRemoteStoreClient>();

            return(builder.WithStore <HttpRemoteStore>(ServiceLifetime.Singleton, endpointTemplate));
        }
 /// <summary>
 /// Adds a ConfigurationStore to the application.
 /// </summary>
 /// <param name="builder">The builder instance.</param>
 /// <param name="configuration">The IConfiguration to load the section from.</param>
 /// <param name="sectionName">The configuration section to load.</param>
 public static FinbuckleMultiTenantBuilder <TTenantInfo> WithConfigurationStore <TTenantInfo>(this FinbuckleMultiTenantBuilder <TTenantInfo> builder,
                                                                                              IConfiguration configuration,
                                                                                              string sectionName)
     where TTenantInfo : class, ITenantInfo, new()
 => builder.WithStore <ConfigurationStore <TTenantInfo> >(ServiceLifetime.Singleton, configuration, sectionName);
Exemplo n.º 8
0
 /// <summary>
 /// Adds a DistributedCacheStore to the application.
 /// </summary>
 /// <param name="slidingExiration">The timespan for a cache entry's sliding expiration.</param>
 public static FinbuckleMultiTenantBuilder <TTenantInfo> WithDistributedCacheStore <TTenantInfo>(this FinbuckleMultiTenantBuilder <TTenantInfo> builder, TimeSpan?slidingExpiration)
     where TTenantInfo : class, ITenantInfo, new()
 {
     return(builder.WithStore <DistributedCacheStore <TTenantInfo> >(ServiceLifetime.Transient, Constants.TenantToken, slidingExpiration));
 }
Exemplo n.º 9
0
 public static FinbuckleMultiTenantBuilder WithEFCoreStore <TEFCoreStoreDbContext>(this FinbuckleMultiTenantBuilder builder, string conn)
     where TEFCoreStoreDbContext : EFCoreStoreDbContext
 {
     builder.Services.AddDbContext <TEFCoreStoreDbContext>(options => options.UseSqlServer(conn));
     return(builder.WithStore <EFCoreStore <TEFCoreStoreDbContext> >(ServiceLifetime.Scoped));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Adds a ConfigurationStore to the application.
 /// </summary>
 /// <param name="configuration">The IConfiguration to load the section from.</param>
 /// <param name="sectionName">The configuration section to load.</param>
 public static FinbuckleMultiTenantBuilder WithConfigurationStore(this FinbuckleMultiTenantBuilder builder,
                                                                  IConfiguration configuration,
                                                                  string sectionName)
 => builder.WithStore <ConfigurationStore>(ServiceLifetime.Singleton, configuration, sectionName);
Exemplo n.º 11
0
 /// <summary>
 /// Adds a ConfigurationStore to the application. Uses the default IConfiguration and section "Finbuckle:MultiTenant:Stores:ConfigurationStore".
 /// </summary>
 public static FinbuckleMultiTenantBuilder WithConfigurationStore(this FinbuckleMultiTenantBuilder builder)
 => builder.WithStore <ConfigurationStore>(ServiceLifetime.Singleton);
Exemplo n.º 12
0
 /// <summary>
 /// Adds an Entity Framework store using the <see cref="DefaultTenantDbContext"/>.
 /// </summary>
 /// <returns>The same MultiTenantBuilder passed into the method.</returns>
 public static FinbuckleMultiTenantBuilder WithDefaultEFStore(this FinbuckleMultiTenantBuilder builder, Action <DbContextOptionsBuilder> options)
 {
     builder.Services.AddDbContext <DefaultTenantDbContext>(options); // Note, will not override existing context if already added.
     return(builder.WithStore <DefaultEFStore>(ServiceLifetime.Scoped));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Adds an Entity Framework store using the <see cref="DefaultTenantDbContext"/> and caches tenants for a configurable period of time.  Uses SqlServer.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static FinbuckleMultiTenantBuilder WithDefaultEFCacheStore(this FinbuckleMultiTenantBuilder builder, string connectionString)
 {
     builder.Services.AddDbContext <DefaultTenantDbContext>(options => options.UseSqlServer(connectionString)); // Note, will not override existing context if already added.
     return(builder.WithStore <DefaultEFCacheStore>(ServiceLifetime.Scoped));
 }