-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-613) Add new options buider extensions to the couchbase caching p…
…rovider
- Loading branch information
1 parent
27949d7
commit 97277cb
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/DotNetToolkit.Repository.Caching.Couchbase/RepositoryOptionsBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace DotNetToolkit.Repository.Caching.Couchbase | ||
{ | ||
using Configuration.Options; | ||
using JetBrains.Annotations; | ||
using System; | ||
using Utility; | ||
|
||
/// <summary> | ||
/// Contains various extension methods for <see cref="RepositoryOptionsBuilder" /> | ||
/// </summary> | ||
public static class RepositoryOptionsBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Configures the caching provider to use couchbase. | ||
/// </summary> | ||
/// <param name="source">The repository options builder.</param> | ||
/// <param name="optionsAction">The options action.</param> | ||
/// <returns>The same builder instance.</returns> | ||
public static RepositoryOptionsBuilder UseCouchbase([NotNull] this RepositoryOptionsBuilder source, [NotNull] Action<CouchbaseCacheOptions> optionsAction) | ||
{ | ||
Guard.NotNull(source, nameof(source)); | ||
Guard.NotNull(optionsAction, nameof(optionsAction)); | ||
|
||
var options = new CouchbaseCacheOptions(); | ||
|
||
optionsAction(options); | ||
|
||
var provider = new CouchbaseCacheProvider( | ||
options.Host, | ||
options.BucketName, | ||
options.Username, | ||
options.Password, | ||
options.Expiry); | ||
|
||
source.UseCachingProvider(provider); | ||
|
||
return source; | ||
} | ||
} | ||
} |