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 18, 2021
1 parent 94592ff commit 034531d
Showing 1 changed file with 40 additions and 0 deletions.
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 034531d

Please sign in to comment.