/// <summary> /// This extension method attaches a memory persistence command to the incoming pipeline. /// </summary> /// <typeparam name="C">The incoming channel type.</typeparam> /// <typeparam name="K">The equatable key type.</typeparam> /// <typeparam name="E">The entity type.</typeparam> /// <param name="cpipe">The incoming channel pipeline.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="credentials">This is the optional azure storage credentials. /// If this is not supplied, the method will try and extract this from configuration using the StorageAccountName and StorageAccountAccessKey keys.</param> /// <param name="startupPriority">The command start-up priority.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="keySerializer">The key serializer function.</param> /// <returns>The pipeline.</returns> public static C AttachPersistenceManagerDocumentDbSdk <C, K, E>(this C cpipe , Func <E, K> keyMaker , Func <string, K> keyDeserializer , DocumentDbConnection connection = null , string database = null , int startupPriority = 100 , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <K, string> keySerializer = null ) where C : IPipelineChannelIncoming <IPipeline> where K : IEquatable <K> { cpipe.Pipeline.AddPersistenceManagerDocumentDbSdk(keyMaker, keyDeserializer, cpipe, connection, database, startupPriority , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , referenceMaker: referenceMaker , keySerializer: keySerializer); return(cpipe); }
/// <summary> /// This is the document db persistence agent. /// </summary> /// <param name="connection">The documentDb connection.</param> /// <param name="database">The is the databaseId name. If the Db does not exist it will be created.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="jsonMaker">This function can be used to override the default JSON creation functions.</param> /// <param name="databaseCollection">The is the collection name. If the collection does it exist it will be created. This will be used by the sharding policy to create multiple collections.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionMaker">This function should be set to enforce optimistic locking.</param> /// <param name="defaultTimeout">This is the default timeout period to be used when connecting to documentDb.</param> /// <param name="shardingPolicy">This is sharding policy used to choose the appropriate collection from the key presented.</param> /// <param name="retryPolicy"></param> public PersistenceManagerHandlerDocumentDbBase( DocumentDbConnection connection , string database , Func <E, K> keyMaker , Func <string, K> keyDeserializer , string databaseCollection = null , ShardingPolicy <K> shardingPolicy = null , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <K, string> keySerializer = null ) : base(entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , keyMaker: keyMaker , referenceMaker: referenceMaker , keySerializer: keySerializer , keyDeserializer: keyDeserializer ) { mConnection = connection; mDatabaseName = database; mCollectionName = databaseCollection ?? typeof(E).Name; mShardingPolicy = shardingPolicy ?? new ShardingPolicy <K>(mCollectionName, (k) => 0, 1, (i) => mCollectionName); }
/// <summary> /// This is the document db persistence agent. /// </summary> /// <param name="connection">The documentDb connection.</param> /// <param name="database">The is the databaseId name. If the Db does not exist it will be created.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="databaseCollection">The is the collection name. If the collection does it exist it will be created. This will be used by the sharding policy to create multiple collections.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionMaker">This function should be set to enforce optimistic locking.</param> /// <param name="defaultTimeout">This is the default timeout period to be used when connecting to documentDb.</param> /// <param name="shardingPolicy">This is sharding policy used to choose the appropriate collection from the key presented.</param> /// <param name="retryPolicy"></param> public PersistenceMessageHandlerDocumentDbSdk(DocumentDbConnection connection , string database , Func <E, K> keyMaker , Func <string, K> keyDeserializer , string databaseCollection = null , ShardingPolicy <K> shardingPolicy = null , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <K, string> keySerializer = null ) : base(connection, database, keyMaker, keyDeserializer , databaseCollection: databaseCollection , shardingPolicy: shardingPolicy , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , keySerializer: keySerializer ) { }
/// <summary> /// This extension method attaches a memory persistence command to the incoming pipeline. /// </summary> /// <typeparam name="P">The incoming channel type.</typeparam> /// <typeparam name="K">The equatable key type.</typeparam> /// <typeparam name="E">The entity type.</typeparam> /// <param name="pipeline">The pipeline.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="cpipe">The incoming channel to listen for requests.</param> /// <param name="startupPriority">The command start-up priority.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="cacheManager">The cache manager.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="referenceHashMaker">The reference hash maker. This is used for fast lookup.</param> /// <param name="keySerializer">The key serializer function.</param> /// <param name="prePopulate">The optional pre-population collection.</param> /// <returns>The pipeline.</returns> public static P AddPersistenceManagerHandlerMemory <P, K, E>(this P pipeline , Func <E, K> keyMaker , Func <string, K> keyDeserializer , IPipelineChannelIncoming <P> cpipe , int startupPriority = 100 , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null , IEnumerable <KeyValuePair <K, E> > prePopulate = null ) where P : IPipeline where K : IEquatable <K> { PersistenceManagerHandlerMemory <K, E> pm = null; return(pipeline.AddPersistenceManagerHandlerMemory(keyMaker, keyDeserializer, cpipe, out pm , startupPriority , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , referenceHashMaker: referenceHashMaker , keySerializer: keySerializer , prePopulate: prePopulate)); }
/// <summary> /// This constructor specifies whether the service should be registered as a shared service /// that can be called directly by other message handler and Microservice components. /// </summary> /// <param name="persistenceRetryPolicy"></param> /// <param name="resourceProfile"></param> /// <param name="cacheManager"></param> /// <param name="defaultTimeout"></param> /// <param name="entityName"></param> /// <param name="versionPolicy"></param> /// <param name="keyMaker"></param> /// <param name="persistenceEntitySerializer"></param> /// <param name="cachingEntitySerializer"></param> /// <param name="keySerializer"></param> /// <param name="keyDeserializer"></param> /// <param name="referenceMaker"></param> /// <param name="referenceHashMaker"></param> protected PersistenceCommandBase( PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , TimeSpan?defaultTimeout = null , string entityName = null , VersionPolicy <E> versionPolicy = null , Func <E, K> keyMaker = null , EntitySerializer <E> persistenceEntitySerializer = null , EntitySerializer <E> cachingEntitySerializer = null , Func <K, string> keySerializer = null , Func <string, K> keyDeserializer = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null ) { mTransform = EntityTransformCreate(entityName, versionPolicy, keyMaker , persistenceEntitySerializer, cachingEntitySerializer , keySerializer, keyDeserializer, referenceMaker, referenceHashMaker); mRequestsCurrent = new ConcurrentDictionary <Guid, IPersistenceRequestHolder>(); mPolicy.DefaultTimeout = defaultTimeout ?? TimeSpan.FromSeconds(10); mPolicy.PersistenceRetryPolicy = persistenceRetryPolicy ?? new PersistenceRetryPolicy(); mPolicy.ResourceProfile = resourceProfile; mCacheManager = cacheManager ?? new NullCacheManager <K, E>(); }
/// <summary> /// This is the default constructor. /// </summary> /// <param name="credentials">The azure storage credentials.</param> /// <param name="keyMaker"></param> /// <param name="keyDeserializer"></param> /// <param name="storageIdMaker"></param> /// <param name="keySerializer"></param> /// <param name="entityName">The options entity name. If this is not presented then the entity name will be used.</param> /// <param name="versionPolicy">The versioning policy.</param> /// <param name="defaultTimeout">The default timeout for async requests.</param> /// <param name="accessType">The azure access type. BlobContainerPublicAccessType.Off is the default.</param> /// <param name="options">The optional blob request options.</param> /// <param name="context">The optional operation context.</param> /// <param name="persistenceRetryPolicy">Persistence retry policy</param> /// <param name="resourceProfile"></param> /// <param name="cacheManager"></param> /// <param name="referenceMaker"></param> /// <param name="encryption"></param> public PersistenceMessageHandlerAzureBlobStorageBase(StorageCredentials credentials , Func <E, K> keyMaker , Func <string, K> keyDeserializer , Func <K, string> storageIdMaker = null , Func <K, string> keySerializer = null , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , BlobContainerPublicAccessType accessType = BlobContainerPublicAccessType.Off , BlobRequestOptions options = null , OperationContext context = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , IServiceHandlerEncryption encryption = null ) : base(keyMaker, keyDeserializer , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , keySerializer: keySerializer ) { mDirectory = entityName ?? typeof(E).Name; mStorage = new StorageServiceBase(credentials, "persistence", accessType, options, context, defaultTimeout: defaultTimeout, encryption: encryption); mStorageIdMaker = storageIdMaker ?? mTransform.KeySerializer; }
/// <summary> /// This is the default constructor with a manual connection string. /// </summary> /// <param name="connection">The sql datbase connection.</param> /// <param name="keyMaker">The key maker function.</param> /// <param name="keyDeserializer"></param> /// <param name="persistenceEntitySerializer">The entity serializer for persistence.</param> /// <param name="cachingEntitySerializer">The entity serializer for caching</param> /// <param name="xmlVersionMaker"></param> /// <param name="entityName"></param> /// <param name="versionPolicy"></param> /// <param name="defaultTimeout"></param> /// <param name="persistenceRetryPolicy"></param> /// <param name="resourceProfile"></param> /// <param name="cacheManager"></param> /// <param name="referenceMaker"></param> /// <param name="referenceHashMaker"></param> /// <param name="keySerializer"></param> protected PersistenceManagerHandlerSqlBase(string connection , Func <E, K> keyMaker , Func <string, K> keyDeserializer , EntitySerializer <E> persistenceEntitySerializer = null , EntitySerializer <E> cachingEntitySerializer = null , Func <XElement, Tuple <K, string> > xmlVersionMaker = null , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null ) : base(connection , keyMaker , keyDeserializer , persistenceEntitySerializer , cachingEntitySerializer , xmlVersionMaker: xmlVersionMaker , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , referenceHashMaker: referenceHashMaker , keySerializer: keySerializer ) { }
/// <summary> /// This is the default constructor for the memory persistence manager. /// This persistence manager is used to hold an in-memory JSON representation of the entity. /// It is primarily used for test purposes, but can be used in a production context. /// Please note that all data will be lost when the service is restarted. /// </summary> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="cacheManager">The cache manager.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="referenceHashMaker">The reference hash maker. This is used for fast lookup.</param> /// <param name="keySerializer">The key serializer function.</param> /// <param name="policy">The policy.</param> /// <param name="prePopulate">The optional pre-population collection.</param> public PersistenceManagerHandlerMemory(Func <E, K> keyMaker , Func <string, K> keyDeserializer , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null , CommandPolicy policy = null , IEnumerable <KeyValuePair <K, E> > prePopulate = null ) : base(keyMaker , keyDeserializer , entityName , versionPolicy , defaultTimeout , persistenceRetryPolicy , resourceProfile , cacheManager , referenceMaker , referenceHashMaker , keySerializer , policy , prePopulate ) { }
/// <summary> /// This extension method attaches a memory persistence command to the incoming pipeline. /// </summary> /// <typeparam name="C">The incoming channel type.</typeparam> /// <typeparam name="K">The equatable key type.</typeparam> /// <typeparam name="E">The entity type.</typeparam> /// <param name="cpipe">The incoming channel pipeline.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="startupPriority">The command start-up priority.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="cacheManager">The cache manager.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="referenceHashMaker">The reference hash maker. This is used for fast lookup.</param> /// <param name="keySerializer">The key serializer function.</param> /// <param name="prePopulate">The optional pre-population collection.</param> /// <returns>The pipeline.</returns> public static C AttachPersistenceManagerHandlerFile <C, K, E>(this C cpipe , Func <E, K> keyMaker , Func <string, K> keyDeserializer , int startupPriority = 100 , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null , IEnumerable <KeyValuePair <K, E> > prePopulate = null ) where C : IPipelineChannelIncoming <IPipeline> where K : IEquatable <K> { PersistenceManagerHandlerFile <K, E> pm = null; return(cpipe.AttachPersistenceManagerHandlerFile(keyMaker, keyDeserializer, out pm , startupPriority , entityName , versionPolicy , defaultTimeout , persistenceRetryPolicy , resourceProfile , cacheManager , referenceMaker , referenceHashMaker , keySerializer , prePopulate)); }
/// <summary> /// This is the document db persistence agent. /// </summary> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer"></param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy"></param> /// <param name="defaultTimeout">This is the default timeout period to be used when connecting to documentDb.</param> /// <param name="persistenceRetryPolicy"></param> /// <param name="resourceProfile"></param> /// <param name="cacheManager"></param> /// <param name="referenceMaker"></param> /// <param name="referenceHashMaker"></param> /// <param name="keySerializer"></param> public PersistenceManagerHandlerMemory(Func <E, K> keyMaker , Func <string, K> keyDeserializer , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null ) : base(keyMaker, keyDeserializer , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , referenceHashMaker: referenceHashMaker , keySerializer: keySerializer ) { }
/// <summary> /// This extension method attaches a memory persistence command to the incoming pipeline. /// </summary> /// <typeparam name="P">The incoming channel type.</typeparam> /// <typeparam name="K">The equatable key type.</typeparam> /// <typeparam name="E">The entity type.</typeparam> /// <param name="pipeline">The pipeline.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="cpipe">The incoming channel to listen for requests.</param> /// <param name="credentials">This is the optional azure storage credentials. /// If this is not supplied, the method will try and extract this from configuration using the StorageAccountName and StorageAccountAccessKey keys.</param> /// <param name="startupPriority">The command start-up priority.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="keySerializer">The key serializer function.</param> /// <returns>The pipeline.</returns> public static P AddPersistenceManagerDocumentDbSdk <P, K, E>(this P pipeline , Func <E, K> keyMaker , Func <string, K> keyDeserializer , IPipelineChannelIncoming <P> cpipe , DocumentDbConnection connection = null , string database = null , int startupPriority = 100 , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <K, string> keySerializer = null ) where P : IPipeline where K : IEquatable <K> { if (keyMaker == null) { throw new ArgumentNullException("keyMaker", $"keyMaker cannot be null in {nameof(AddPersistenceManagerDocumentDbSdk)}"); } if (keyDeserializer == null) { throw new ArgumentNullException("keyDeserializer", $"keyDeserializer cannot be null in {nameof(AddPersistenceManagerDocumentDbSdk)}"); } if (cpipe == null) { throw new ArgumentNullException("cpipe", $"cpipe cannot be null in {nameof(AddPersistenceManagerDocumentDbSdk)}"); } if (connection == null) { connection = pipeline.Configuration.DocDBConnection(true); } if (database == null) { database = pipeline.Configuration.DocDBDatabaseName(false); } var pm = new PersistenceMessageHandlerDocumentDbSdk <K, E>(connection, database, keyMaker, keyDeserializer , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , referenceMaker: referenceMaker , keySerializer: keySerializer ); pipeline.AddCommand(pm, startupPriority, channelIncoming: cpipe); return(pipeline); }
/// <summary> /// This extension method attaches a memory persistence command to the incoming pipeline. /// </summary> /// <typeparam name="P">The incoming channel type.</typeparam> /// <typeparam name="K">The equatable key type.</typeparam> /// <typeparam name="E">The entity type.</typeparam> /// <param name="pipeline">The pipeline.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="cpipe">The incoming channel to listen for requests.</param> /// <param name="pm">An output parameter for the persistence manager.</param> /// <param name="startupPriority">The command start-up priority.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="cacheManager">The cache manager.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="referenceHashMaker">The reference hash maker. This is used for fast lookup.</param> /// <param name="keySerializer">The key serializer function.</param> /// <param name="prePopulate">The optional pre-population collection.</param> /// <returns>The pipeline.</returns> public static P AddPersistenceManagerHandlerMemory <P, K, E>(this P pipeline , Func <E, K> keyMaker , Func <string, K> keyDeserializer , IPipelineChannelIncoming <P> cpipe , out PersistenceManagerHandlerMemory <K, E> pm , int startupPriority = 100 , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null , IEnumerable <KeyValuePair <K, E> > prePopulate = null ) where P : IPipeline where K : IEquatable <K> { if (keyMaker == null) { throw new ArgumentNullException("keyMaker", $"keyMaker cannot be null in {nameof(AddPersistenceManagerHandlerMemory)}"); } if (keyDeserializer == null) { throw new ArgumentNullException("keyDeserializer", $"keyDeserializer cannot be null in {nameof(AddPersistenceManagerHandlerMemory)}"); } if (cpipe == null) { throw new ArgumentNullException("cpipe", $"cpipe cannot be null in {nameof(AddPersistenceManagerHandlerMemory)}"); } pm = new PersistenceManagerHandlerMemory <K, E>(keyMaker, keyDeserializer , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , referenceHashMaker: referenceHashMaker , keySerializer: keySerializer , prePopulate: prePopulate); pipeline.AddCommand(pm, startupPriority, channelIncoming: cpipe); return(pipeline); }
/// <summary> /// This constructor specifies whether the service should be registered as a shared service /// that can be called directly by other message handler and Microservice components. /// </summary> protected PersistenceCommandBase( EntityTransformHolder <K, E> entityTransform , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , TimeSpan?defaultTimeout = null ) { if (entityTransform == null) { throw new ArgumentNullException("entityTransform cannot be null"); } mTransform = entityTransform; mPolicy.DefaultTimeout = defaultTimeout ?? TimeSpan.FromSeconds(10); mPolicy.PersistenceRetryPolicy = persistenceRetryPolicy ?? new PersistenceRetryPolicy(); mPolicy.ResourceProfile = resourceProfile; mCacheManager = cacheManager ?? new NullCacheManager <K, E>(); }
/// <summary> /// This is the default constructor. /// </summary> /// <param name="keyDeserializer"></param> /// <param name="entityName">The entity name, derived from E if left null.</param> /// <param name="versionPolicy">The optional version and locking policy.</param> /// <param name="defaultTimeout">The default timeout when making requests.</param> /// <param name="redisConnection"></param> /// <param name="keyMaker"></param> /// <param name="persistenceRetryPolicy"></param> /// <param name="resourceProfile"></param> /// <param name="referenceMaker"></param> /// <param name="keySerializer"></param> public PersistenceMessageHandlerRedisCache(string redisConnection , Func <E, K> keyMaker , Func <string, K> keyDeserializer , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <K, string> keySerializer = null ) : base(entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: RedisCacheHelper.Default <K, E>(redisConnection) , keyMaker: keyMaker , referenceMaker: referenceMaker , keySerializer: keySerializer , keyDeserializer: keyDeserializer) { }