Skip to content

Commit e0384c5

Browse files
Merge pull request #667 from johelvisguzman/GH-665
GH-665
2 parents f300d88 + 197e95c commit e0384c5

File tree

18 files changed

+162
-65
lines changed

18 files changed

+162
-65
lines changed

src/DotNetToolkit.Repository.AzureStorageBlob/Internal/AzureStorageBlobRepositoryContext.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,7 @@ public AzureStorageBlobRepositoryContext(string connectionString, IAzureStorageB
5151

5252
private JsonSerializer GetJsonSerializer()
5353
{
54-
var settings = _serializerSettings ?? new JsonSerializerSettings
55-
{
56-
Formatting = Formatting.Indented,
57-
ContractResolver = new DefaultJsonSerializeContractResolver(),
58-
PreserveReferencesHandling = PreserveReferencesHandling.None
59-
};
60-
61-
return JsonSerializer.Create(settings);
54+
return JsonSerializer.Create(_serializerSettings);
6255
}
6356

6457
private Stream Serialize<TEntity>(TEntity entity)

src/DotNetToolkit.Repository.AzureStorageBlob/Internal/DefaultJsonSerializeContractResolver.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/DotNetToolkit.Repository.Caching.Couchbase/CouchbaseCacheOptions.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace DotNetToolkit.Repository.Caching.Couchbase
22
{
3+
using global::Couchbase.Core.Serialization;
34
using JetBrains.Annotations;
45
using System;
56
using Utility;
@@ -14,6 +15,7 @@ public class CouchbaseCacheOptions
1415
private string _username;
1516
private string _password;
1617
private TimeSpan? _expiry;
18+
private Func<ITypeSerializer> _serializer;
1719

1820
/// <summary>
1921
/// Gets the host.
@@ -40,6 +42,11 @@ public class CouchbaseCacheOptions
4042
/// </summary>
4143
public TimeSpan? Expiry { get { return _expiry; } }
4244

45+
/// <summary>
46+
/// Gets the serializer.
47+
/// </summary>
48+
public Func<ITypeSerializer> Serializer { get { return _serializer; } }
49+
4350
/// <summary>
4451
/// Adds the giving bucketname to the options.
4552
/// </summary>
@@ -90,7 +97,7 @@ public CouchbaseCacheOptions WithEndPoint([NotNull] string host, int port)
9097
/// <summary>
9198
/// Adds the giving endpoint to the options.
9299
/// </summary>
93-
/// <param name="hostAndPort">The host and port to be added.</param>
100+
/// <param name="hostAndPort">The address and the port of the server in the format 'host:port' to be added.</param>
94101
public CouchbaseCacheOptions WithEndPoint([NotNull] string hostAndPort)
95102
{
96103
_host = Guard.NotEmpty(hostAndPort, nameof(hostAndPort));
@@ -108,5 +115,17 @@ public CouchbaseCacheOptions WithExpiry([NotNull] TimeSpan expiry)
108115

109116
return this;
110117
}
118+
119+
/// <summary>
120+
/// Adds the giving json serializer settings to the options.
121+
/// </summary>
122+
/// <param name="serializer">The serializer to be added.</param>
123+
/// <returns>The new options instance with the given json serializer settings added.</returns>
124+
public CouchbaseCacheOptions WithSerializer([NotNull] Func<ITypeSerializer> serializer)
125+
{
126+
_serializer = Guard.NotNull(serializer, nameof(serializer));
127+
128+
return this;
129+
}
111130
}
112131
}

src/DotNetToolkit.Repository.Caching.Couchbase/CouchbaseCacheProvider.cs renamed to src/DotNetToolkit.Repository.Caching.Couchbase/Internal/CouchbaseCacheProvider.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
namespace DotNetToolkit.Repository.Caching.Couchbase
1+
namespace DotNetToolkit.Repository.Caching.Couchbase.Internal
22
{
33
using Configuration.Caching;
44
using global::Couchbase;
55
using global::Couchbase.Configuration.Client;
6+
using global::Couchbase.Core.Serialization;
7+
using Newtonsoft.Json;
68
using System;
79
using System.Collections.Generic;
810
using Utility;
@@ -24,8 +26,8 @@ internal class CouchbaseCacheProvider : ICacheProvider
2426

2527
#region Constructors
2628

27-
public CouchbaseCacheProvider(string host, string bucketName, string username, string password, TimeSpan? expiry)
28-
: this(GetConfigurationOptions(host, bucketName, username, password), expiry) { }
29+
public CouchbaseCacheProvider(string host, string bucketName, string username, string password, TimeSpan? expiry, Func<ITypeSerializer> serializer)
30+
: this(GetConfigurationOptions(host, bucketName, username, password, serializer), expiry) { }
2931

3032
private CouchbaseCacheProvider(ClientConfiguration config, TimeSpan? expiry)
3133
{
@@ -37,7 +39,7 @@ private CouchbaseCacheProvider(ClientConfiguration config, TimeSpan? expiry)
3739

3840
#region Private Methods
3941

40-
private static ClientConfiguration GetConfigurationOptions(string host, string username, string password, string bucketName)
42+
private static ClientConfiguration GetConfigurationOptions(string host, string username, string password, string bucketName, Func<ITypeSerializer> serializer)
4143
{
4244
var config = new ClientConfiguration();
4345
var bucket = !string.IsNullOrEmpty(bucketName) ? bucketName : DefaultBucketName;
@@ -61,6 +63,11 @@ private static ClientConfiguration GetConfigurationOptions(string host, string u
6163
}
6264
};
6365

66+
if (serializer != null)
67+
{
68+
config.Serializer = serializer;
69+
}
70+
6471
return config;
6572
}
6673

src/DotNetToolkit.Repository.Caching.Couchbase/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ var options = new RepositoryOptionsBuilder()
77

88
var repo = new Repository<Customer>(options);
99
```
10+
11+
# Configuration Options
12+
13+
|Action|Description|
14+
|------|-----------|
15+
|WithUserName|The user name|
16+
|WithPassword|The password|
17+
|WithBucketName|The bucket name|
18+
|WithEndPoint|The host name or IP address of the server|
19+
|WithExpiry|Expiration time|
20+
|WithSerializer|The serializer|

src/DotNetToolkit.Repository.Caching.Couchbase/RepositoryOptionsBuilderExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace DotNetToolkit.Repository.Caching.Couchbase
22
{
33
using Configuration.Options;
4+
using Internal;
45
using JetBrains.Annotations;
56
using System;
67
using Utility;
@@ -30,7 +31,8 @@ public static RepositoryOptionsBuilder UseCouchbase([NotNull] this RepositoryOpt
3031
options.BucketName,
3132
options.Username,
3233
options.Password,
33-
options.Expiry);
34+
options.Expiry,
35+
options.Serializer);
3436

3537
source.UseCachingProvider(provider);
3638

src/DotNetToolkit.Repository.Caching.InMemory/InMemoryCacheOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public InMemoryCacheOptions WithClock([NotNull] ISystemClock clock)
4141
}
4242

4343
/// <summary>
44-
/// Adds the giving system clock vaue to the options.
44+
/// Adds the minimum length of time between successive scans for expired items vaue to the options.
4545
/// </summary>
4646
/// <param name="expirationScanFrequency">The minimum length of time between successive scans for expired items to be added.</param>
4747
public InMemoryCacheOptions WithExpirationScanFrequency([NotNull] TimeSpan expirationScanFrequency)

src/DotNetToolkit.Repository.Caching.InMemory/InMemoryCacheProvider.cs renamed to src/DotNetToolkit.Repository.Caching.InMemory/Internal/InMemoryCacheProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace DotNetToolkit.Repository.Caching.InMemory
1+
namespace DotNetToolkit.Repository.Caching.InMemory.Internal
22
{
33
using Configuration.Caching;
44
using JetBrains.Annotations;

src/DotNetToolkit.Repository.Caching.InMemory/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ var options = new RepositoryOptionsBuilder()
77

88
var repo = new Repository<Customer>(options);
99
```
10+
11+
# Configuration Options
12+
13+
|Action|Description|
14+
|------|-----------|
15+
|WithClock|System clock|
16+
|WithExpirationScanFrequency|Minimum length of time between successive scans for expired items|
17+
|WithExpiry|Expiration time|

src/DotNetToolkit.Repository.Caching.InMemory/RepositoryOptionsBuilderExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace DotNetToolkit.Repository.Caching.InMemory
22
{
33
using Configuration.Options;
4+
using Internal;
45
using JetBrains.Annotations;
56
using System;
67
using Utility;

0 commit comments

Comments
 (0)