Skip to content

Commit

Permalink
(GH-613) Add new options buider extensions to the couchbase caching p…
Browse files Browse the repository at this point in the history
…rovider
  • Loading branch information
johelvisguzman committed Oct 19, 2021
1 parent 27949d7 commit 97277cb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DotNetToolkit.Repository.Caching.Couchbase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

```csharp
var options = new RepositoryOptionsBuilder()
.UseCachingProvider(new CouchbaseCacheProvider())
.UseCouchbase(...)
.Options;

var repo = new Repository<Customer>(options);
Expand Down
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;
}
}
}

0 comments on commit 97277cb

Please sign in to comment.