/// <summary>
 /// Provides the state manager to the persistence.
 /// </summary>
 /// <param name="configuration">The persistence extension.</param>
 /// <param name="stateManager">The state manager to be used.</param>
 /// <param name="transactionTimeout">The transaction timeout. The default is 4 seconds.</param>
 public static void StateManager(this PersistenceExtensions <ServiceFabricPersistence> configuration, IReliableStateManager stateManager, TimeSpan?transactionTimeout = null)
 {
     Guard.AgainstNull(nameof(configuration), configuration);
     Guard.AgainstNull(nameof(stateManager), stateManager);
     configuration.GetSettings().Set("ServiceFabricPersistence.StateManager", stateManager);
     configuration.GetSettings().Set("ServiceFabricPersistence.StateManager.TransactionTimeout", stateManager);
 }
示例#2
0
 /// <summary>
 /// Configures how <see cref="DbConnection"/>s are constructed.
 /// </summary>
 public static void ConnectionBuilder(this PersistenceExtensions <SqlPersistence> configuration, Func <DbConnection> connectionBuilder)
 {
     Guard.AgainstNull(nameof(configuration), configuration);
     Guard.AgainstNull(nameof(connectionBuilder), connectionBuilder);
     configuration.GetSettings()
     .Set("SqlPersistence.ConnectionBuilder", connectionBuilder);
 }
示例#3
0
        /// <summary>
        /// Configures the location where sagas are stored.
        /// </summary>
        /// <param name="persistenceExtensions">The persistence extensions to extend.</param>
        /// <param name="path">The storage path.</param>
        public static void SagaStorageDirectory(this PersistenceExtensions <LearningPersistence> persistenceExtensions, string path)
        {
            Guard.AgainstNull(nameof(persistenceExtensions), persistenceExtensions);
            Guard.AgainstNullAndEmpty(nameof(path), path);

            persistenceExtensions.Settings.Set(LearningSagaPersistence.StorageLocationKey, path);
        }
        /// <summary>
        /// Configure whether the persistence should use MongoDB transactions
        /// </summary>
        public static PersistenceExtensions <MongoPersistence> UseTransactions(this PersistenceExtensions <MongoPersistence> persistenceExtensions, bool useTransactions)
        {
            Guard.AgainstNull(nameof(persistenceExtensions), persistenceExtensions);

            persistenceExtensions.GetSettings().Set(SettingsKeys.UseTransactions, useTransactions);
            return(persistenceExtensions);
        }
        /// <summary>
        /// Configures the queue used to store subscriptions.
        /// </summary>
        /// <param name="persistenceExtensions">The settings to extend.</param>
        /// <param name="queue">The queue name.</param>
        public static void SubscriptionQueue(this PersistenceExtensions <MsmqPersistence> persistenceExtensions, string queue)
        {
            Guard.AgainstNull(nameof(persistenceExtensions), persistenceExtensions);
            Guard.AgainstNull(nameof(queue), queue);

            persistenceExtensions.GetSettings().Set(MsmqPersistenceQueueConfigurationKey, queue);
        }
        /// <summary>
        /// Sets the <see cref="SqlVariant"/> to use for communicating the the current database.
        /// </summary>
        public static void SqlVariant(this PersistenceExtensions <SqlPersistence> configuration, SqlVariant sqlVariant)
        {
            Guard.AgainstNull(nameof(configuration), configuration);
            var settings = configuration.GetSettings();

            settings.Set("SqlPersistence.SqlVariant", sqlVariant);
        }
        /// <summary>
        /// Sets the default container name and the partition key path that will be used.
        /// </summary>
        /// <remarks>When the default container is not set the container information needs to be provided as part of the message handling pipeline.</remarks>
        public static PersistenceExtensions <CosmosPersistence> DefaultContainer(this PersistenceExtensions <CosmosPersistence> persistenceExtensions, string containerName, string partitionKeyPath)
        {
            Guard.AgainstNull(nameof(persistenceExtensions), persistenceExtensions);

            persistenceExtensions.GetSettings().Set(new ContainerInformation(containerName, new PartitionKeyPath(partitionKeyPath)));

            return(persistenceExtensions);
        }
        /// <summary>
        /// Disables the container creation.
        /// </summary>
        public static void DisableContainerCreation(this PersistenceExtensions <CosmosPersistence> persistenceExtensions)
        {
            Guard.AgainstNull(nameof(persistenceExtensions), persistenceExtensions);

            var installerSettings = persistenceExtensions.GetSettings().GetOrCreate <InstallerSettings>();

            installerSettings.Disabled = true;
        }
 /// <summary>
 /// Configures the table prefix to be prepended to all Saga, Timeout, Subscription and Outbox tables.
 /// </summary>
 public static void TablePrefix(this PersistenceExtensions <SqlPersistence> configuration, string tablePrefix)
 {
     Guard.AgainstNull(nameof(configuration), configuration);
     Guard.AgainstNull(nameof(tablePrefix), tablePrefix);
     Guard.AgainstSqlDelimiters(nameof(tablePrefix), tablePrefix);
     configuration.GetSettings()
     .Set("SqlPersistence.TablePrefix", tablePrefix);
 }
        /// <summary>
        /// Override the default MongoClient creation by providing a pre-configured IMongoClient
        /// </summary>
        public static PersistenceExtensions <MongoPersistence> MongoClient(this PersistenceExtensions <MongoPersistence> persistenceExtensions, IMongoClient mongoClient)
        {
            Guard.AgainstNull(nameof(persistenceExtensions), persistenceExtensions);
            Guard.AgainstNull(nameof(mongoClient), mongoClient);

            persistenceExtensions.GetSettings().Set(SettingsKeys.MongoClient, (Func <IMongoClient>)(() => mongoClient));
            return(persistenceExtensions);
        }
 /// <summary>
 /// Configures the database schema to be used.
 /// </summary>
 public static void Schema(this PersistenceExtensions <SqlPersistence> configuration, string schema)
 {
     Guard.AgainstNull(nameof(configuration), configuration);
     Guard.AgainstNullAndEmpty(nameof(schema), schema);
     Guard.AgainstSqlDelimiters(nameof(schema), schema);
     configuration.GetSettings()
     .Set("SqlPersistence.Schema", schema);
 }
        /// <summary>
        /// Override the default database used by the persistence
        /// </summary>
        public static PersistenceExtensions <MongoPersistence> DatabaseName(this PersistenceExtensions <MongoPersistence> persistenceExtensions, string databaseName)
        {
            Guard.AgainstNull(nameof(persistenceExtensions), persistenceExtensions);
            Guard.AgainstNullAndEmpty(nameof(databaseName), databaseName);

            persistenceExtensions.GetSettings().Set(SettingsKeys.DatabaseName, databaseName);
            return(persistenceExtensions);
        }
示例#13
0
        /// <summary>
        /// Disables the SQL persistence installers.
        /// </summary>
        public static void DisableInstaller(this PersistenceExtensions <SqlPersistence> configuration)
        {
            Guard.AgainstNull(nameof(configuration), configuration);

            var installerSettings = configuration.GetSettings().GetOrCreate <InstallerSettings>();

            installerSettings.Disabled = true;
        }
示例#14
0
        static void SetLegacyVersionedSubscriptions(PersistenceExtensions <RavenDBPersistence> cfg, bool value)
        {
            var settings = cfg.GetSettings();

            if (settings.TryGet(LegacySubscriptionVersioningKey, out bool existingSetting) && existingSetting != value)
            {
                throw new Exception("RavenDB Persistence options `persistence.DisableSubscriptionVersioning()` and `persistence.UseLegacyVersionedSubscriptions()` can't be used simultaneously.");
            }
            settings.Set(LegacySubscriptionVersioningKey, value);
        }
        /// <summary>
        /// Override the default CosmosClient creation by providing a pre-configured CosmosClient
        /// </summary>
        /// <remarks>The lifetime of the provided client is assumed to be controlled by the caller of this method and thus the client will not be disposed.</remarks>
        public static PersistenceExtensions <CosmosPersistence> CosmosClient(this PersistenceExtensions <CosmosPersistence> persistenceExtensions, CosmosClient cosmosClient)
        {
            Guard.AgainstNull(nameof(persistenceExtensions), persistenceExtensions);
            Guard.AgainstNull(nameof(cosmosClient), cosmosClient);

            persistenceExtensions.GetSettings().Set <IProvideCosmosClient>(new CosmosClientProvidedByConfiguration {
                Client = cosmosClient
            });
            return(persistenceExtensions);
        }
示例#16
0
        /// <summary>
        /// Forces the peristence to not reuse the EventStore transport connection string and use its own.
        /// </summary>
        /// <param name="persistence">Persistence extensions.</param>
        /// <param name="connectionString">Connection string.</param>
        public static PersistenceExtensions <EventStorePersistence> ConnectionString(this PersistenceExtensions <EventStorePersistence> persistence, string connectionString)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }
            var config = new ConnectionStringParser().Parse(connectionString);

            persistence.GetSettings().Set(OutboxPersisterFeature.ConnectionConfigurationSettingsKey, config);
            return(persistence);
        }
        /// <summary>
        /// Configures how <see cref="DbConnection"/>s are constructed, allowing for selecting a different database per tenant in a multi-tenant system.
        /// </summary>
        /// <param name="configuration">The persistence configuration object</param>
        /// <param name="tenantIdHeaderName">The name of the message header that identifies the tenant id in each message.</param>
        /// <param name="buildConnectionFromTenantData">Using a tenant id, builds a database connection for that tenant database.</param>
        public static void MultiTenantConnectionBuilder(this PersistenceExtensions <SqlPersistence> configuration, string tenantIdHeaderName, Func <string, DbConnection> buildConnectionFromTenantData)
        {
            var captureTenantId = new Func <IncomingMessage, string>(incomingMessage =>
            {
                if (incomingMessage.Headers.TryGetValue(tenantIdHeaderName, out var tenantId))
                {
                    return(tenantId);
                }

                return(null);
            });

            MultiTenantConnectionBuilder(configuration, captureTenantId, buildConnectionFromTenantData);
        }
        /// <summary>
        /// Configures how <see cref="DbConnection"/>s are constructed, allowing for selecting a different database per tenant in a multi-tenant system.
        /// </summary>
        /// <param name="configuration">The persistence configuration object</param>
        /// <param name="captureTenantId">Determines the the TenantId based on the incoming message, with the ability to consider multiple message headers or transition from one header to another.</param>
        /// <param name="buildConnectionFromTenantData">Using a tenant id, builds a database connection for that tenant database.</param>
        public static void MultiTenantConnectionBuilder(this PersistenceExtensions <SqlPersistence> configuration, Func <IncomingMessage, string> captureTenantId, Func <string, DbConnection> buildConnectionFromTenantData)
        {
            Guard.AgainstNull(nameof(configuration), configuration);
            Guard.AgainstNull(nameof(captureTenantId), captureTenantId);
            Guard.AgainstNull(nameof(buildConnectionFromTenantData), buildConnectionFromTenantData);

            var connectionManager = new MultiTenantConnectionManager(captureTenantId, buildConnectionFromTenantData);

            var settings = configuration.GetSettings();

            settings.Set($"SqlPersistence.ConnectionManager.{nameof(StorageType.Outbox)}", connectionManager);
            settings.Set($"SqlPersistence.ConnectionManager.{nameof(StorageType.Sagas)}", connectionManager);
            settings.Set("SqlPersistence.MultiTenant", true);
        }
        /// <summary>
        /// Configures which database engine to target.
        /// </summary>
        /// <returns>Settings options available for the selected database engine.</returns>
        public static SqlDialectSettings <T> SqlDialect <T>(this PersistenceExtensions <SqlPersistence> configuration)
            where T : SqlDialect, new()
        {
            var settings = configuration.GetSettings();

            if (settings.TryGet("SqlPersistence.SqlDialect", out SqlDialectSettings <T> dialectSettings))
            {
                return(dialectSettings);
            }

            var type = typeof(SqlDialectSettings <>).MakeGenericType(typeof(T));

            dialectSettings = (SqlDialectSettings <T>)Activator.CreateInstance(type);
            settings.Set("SqlPersistence.SqlDialect", dialectSettings);
            return(dialectSettings);
        }
示例#20
0
 public static void GatewayDeduplicationCacheSize(this PersistenceExtensions <InMemoryPersistence> persistenceExtensions, int maxSize)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 ///     Tells the persister to not setup user permissions for the database
 /// </summary>
 /// <param name="cfg"></param>
 /// <returns></returns>
 public static PersistenceExtensions <RavenDBPersistence> DoNotSetupDatabasePermissions(this PersistenceExtensions <RavenDBPersistence> cfg)
 {
     cfg.GetSettings().Set("RavenDB.DoNotSetupPermissions", true);
     return(cfg);
 }
 /// <summary>
 ///     Specifies the mapping to use for when resolving the database name to use for each message.
 /// </summary>
 /// <param name="cfg">The configuration object.</param>
 /// <param name="convention">
 ///     The method referenced by a Func delegate for finding the database name for the specified
 ///     message.
 /// </param>
 /// <returns>The configuration object.</returns>
 public static PersistenceExtensions <RavenDBPersistence> SetMessageToDatabaseMappingConvention(this PersistenceExtensions <RavenDBPersistence> cfg, Func <IDictionary <string, string>, string> convention)
 {
     cfg.GetSettings().Set("RavenDB.SetMessageToDatabaseMappingConvention", convention);
     return(cfg);
 }
 /// <summary>
 ///     Specifies the async session that the shared persisters (saga + outbox) that should be used. The lifecycle is controlled by
 ///     me
 /// </summary>
 /// <param name="cfg"></param>
 /// <param name="getAsyncSessionFunc">A func returning the async session to be used</param>
 /// <returns></returns>
 public static PersistenceExtensions <RavenDBPersistence> UseSharedAsyncSession(this PersistenceExtensions <RavenDBPersistence> cfg, Func <IDictionary <string, string>, IAsyncDocumentSession> getAsyncSessionFunc)
 {
     if (getAsyncSessionFunc == null)
     {
         throw new ArgumentNullException(nameof(getAsyncSessionFunc));
     }
     cfg.GetSettings().Set(SharedAsyncSessionSettingsKey, getAsyncSessionFunc);
     return(cfg);
 }
 public static PersistenceExtensions <RavenDBPersistence> SetDefaultDocumentStore(this PersistenceExtensions <RavenDBPersistence> cfg, ConnectionParameters connectionParameters)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 ///     Configures the storages to use the given document store supplied
 /// </summary>
 /// <param name="cfg"></param>
 /// <param name="storeCreator">A Func that will create the document store on NServiceBus initialization.</param>
 /// <returns></returns>
 public static PersistenceExtensions <RavenDBPersistence> SetDefaultDocumentStore(this PersistenceExtensions <RavenDBPersistence> cfg, Func <ReadOnlySettings, IDocumentStore> storeCreator)
 {
     DocumentStoreManager.SetDefaultStore(cfg.GetSettings(), storeCreator);
     return(cfg);
 }
 /// <summary>
 ///     Configures the storages to use the given document store supplied
 /// </summary>
 /// <param name="cfg"></param>
 /// <param name="documentStore">Document store managed by me as a user</param>
 /// <returns></returns>
 public static PersistenceExtensions <RavenDBPersistence> SetDefaultDocumentStore(this PersistenceExtensions <RavenDBPersistence> cfg, IDocumentStore documentStore)
 {
     DocumentStoreManager.SetDefaultStore(cfg.GetSettings(), documentStore);
     return(cfg);
 }
 public static SagaSettings SagaSettings(this PersistenceExtensions <ServiceFabricPersistence> configuration)
 {
     return(new SagaSettings(configuration.GetSettings()));
 }
示例#28
0
 public static PersistenceExtensions <RavenDBPersistence> UseLegacyVersionedSubscriptions(this PersistenceExtensions <RavenDBPersistence> cfg)
 {
     SetLegacyVersionedSubscriptions(cfg, true);
     return(cfg);
 }
示例#29
0
 /// <summary>
 /// Do not include message assembly major version in subscription document lookup key.
 /// Subscription behavior will be changed such that all existing subscriptions will be rendered invalid.
 /// Do not enable in an existing system without converting subscription documents first.
 /// </summary>
 /// <param name="cfg"></param>
 /// <returns></returns>
 public static PersistenceExtensions <RavenDBPersistence> DisableSubscriptionVersioning(this PersistenceExtensions <RavenDBPersistence> cfg)
 {
     SetLegacyVersionedSubscriptions(cfg, false);
     return(cfg);
 }
示例#30
0
 /// <summary>
 /// Change the amount of time that Subscription information is cached in-memory. Uses the RavenDB Aggresive Caching feature,
 /// so RavenDB server will send notifications to the client when subscriptions change before the cache duration expires,
 /// however these notifications are not 100% reliable. Default duration is 1 minute.
 /// </summary>
 /// <param name="cfg"></param>
 /// <param name="aggressiveCacheDuration"></param>
 /// <returns></returns>
 public static PersistenceExtensions <RavenDBPersistence> CacheSubscriptionsFor(this PersistenceExtensions <RavenDBPersistence> cfg, TimeSpan aggressiveCacheDuration)
 {
     cfg.GetSettings().Set(AggressiveCacheDurationSettingsKey, aggressiveCacheDuration);
     return(cfg);
 }