Skip to content

Commit 4a9f55e

Browse files
authored
Merge pull request #306 from loresoft/feature/services
Feature/services
2 parents 8b8a981 + aab58db commit 4a9f55e

34 files changed

+681
-269
lines changed

src/FluentCommand.Caching/DistributedDataCache.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace FluentCommand.Caching;
1010

1111
/// <summary>
12-
/// Distributed cache implemenation
12+
/// Distributed data cache implementation
1313
/// </summary>
1414
/// <seealso cref="FluentCommand.IDataCache" />
1515
public partial class DistributedDataCache : IDataCache
@@ -40,7 +40,7 @@ public DistributedDataCache(ILogger<DistributedDataCache> logger, IDistributedCa
4040
/// <para>Success is true if the key was found; otherwise false</para>
4141
/// <para>Value is the cache entry that is identified by key</para>
4242
/// </returns>
43-
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
43+
/// <exception cref="System.ArgumentException">key cannot be null or empty. - key</exception>
4444
public (bool Success, T Value) Get<T>(string key)
4545
{
4646
if (string.IsNullOrEmpty(key))
@@ -71,7 +71,7 @@ public DistributedDataCache(ILogger<DistributedDataCache> logger, IDistributedCa
7171
/// <para>Success is true if the key was found; otherwise false</para>
7272
/// <para>Value is the cache entry that is identified by key</para>
7373
/// </returns>
74-
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
74+
/// <exception cref="System.ArgumentException">'key' cannot be null or empty. - key</exception>
7575
public async Task<(bool Success, T Value)> GetAsync<T>(string key, CancellationToken cancellationToken = default)
7676
{
7777
if (string.IsNullOrEmpty(key))
@@ -104,7 +104,7 @@ public DistributedDataCache(ILogger<DistributedDataCache> logger, IDistributedCa
104104
/// <param name="value">The object to insert into cache.</param>
105105
/// <param name="absoluteExpiration">The fixed date and time at which the cache entry will expire.</param>
106106
/// <param name="slidingExpiration">A value that indicates whether a cache entry should be evicted if it has not been accessed in a given span of time.</param>
107-
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
107+
/// <exception cref="System.ArgumentException">'key' cannot be null or empty. - key</exception>
108108
/// <exception cref="System.ArgumentNullException">value</exception>
109109
public void Set<T>(string key, T value, DateTimeOffset? absoluteExpiration = null, TimeSpan? slidingExpiration = null)
110110
{
@@ -136,7 +136,7 @@ public void Set<T>(string key, T value, DateTimeOffset? absoluteExpiration = nul
136136
/// <param name="absoluteExpiration">The fixed date and time at which the cache entry will expire.</param>
137137
/// <param name="slidingExpiration">A value that indicates whether a cache entry should be evicted if it has not been accessed in a given span of time.</param>
138138
/// <param name="cancellationToken">The cancellation instruction.</param>
139-
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
139+
/// <exception cref="System.ArgumentException">'key' cannot be null or empty. - key</exception>
140140
/// <exception cref="System.ArgumentNullException">value</exception>
141141
public async Task SetAsync<T>(string key, T value, DateTimeOffset? absoluteExpiration = null, TimeSpan? slidingExpiration = null, CancellationToken cancellationToken = default)
142142
{
@@ -168,7 +168,7 @@ await _distributedCache
168168
/// Removes the cache entry from the cache
169169
/// </summary>
170170
/// <param name="key">A unique identifier for the cache entry.</param>
171-
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
171+
/// <exception cref="System.ArgumentException">'key' cannot be null or empty. - key</exception>
172172
public void Remove(string key)
173173
{
174174
if (string.IsNullOrEmpty(key))
@@ -184,7 +184,7 @@ public void Remove(string key)
184184
/// </summary>
185185
/// <param name="key">A unique identifier for the cache entry.</param>
186186
/// <param name="cancellationToken">The cancellation instruction.</param>
187-
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
187+
/// <exception cref="System.ArgumentException">'key' cannot be null or empty. - key</exception>
188188
public async Task RemoveAsync(string key, CancellationToken cancellationToken = default)
189189
{
190190
if (string.IsNullOrEmpty(key))

src/FluentCommand.Caching/FluentCommand.Caching.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="MessagePack" Version="2.5.124" />
8+
<PackageReference Include="MessagePack" Version="2.5.129" />
99
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0" />
1010
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
1111
</ItemGroup>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using MessagePack;
2+
using MessagePack.Resolvers;
3+
4+
using Microsoft.Extensions.DependencyInjection.Extensions;
5+
6+
namespace FluentCommand.Caching;
7+
8+
public static class ServiceCollectionExtensions
9+
{
10+
public static DataConfigurationBuilder AddDistributedDataCache(this DataConfigurationBuilder builder)
11+
{
12+
builder.AddService(sp =>
13+
{
14+
sp.TryAddSingleton(ContractlessStandardResolver.Options.WithCompression(MessagePackCompression.Lz4BlockArray));
15+
sp.TryAddSingleton<IDistributedCacheSerializer, MessagePackCacheSerializer>();
16+
});
17+
18+
builder.AddDataCache<DistributedDataCache>();
19+
20+
return builder;
21+
}
22+
}

src/FluentCommand.Generators/DataReaderFactoryWriter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ private static void WriteEntityFactory(IndentedStringBuilder codeBuilder, Entity
323323
.Append(aliasType)
324324
.Append(" v_")
325325
.Append(fieldName)
326-
.AppendLine(" = default;");
326+
.Append(" = default")
327+
.AppendIf("!", _ => !entityProperty.PropertyType.EndsWith("?"))
328+
.AppendLine(";");
327329
}
328330

329331
codeBuilder

src/FluentCommand.Generators/FluentCommand.Generators.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<AnalyzerLanguage>cs</AnalyzerLanguage>
1414
<AnalyzerRoslynVersion>4.3</AnalyzerRoslynVersion>
1515
<LangVersion>latest</LangVersion>
16+
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
1617
</PropertyGroup>
1718

1819
<ItemGroup>

src/FluentCommand.Generators/IndentedStringBuilder.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,49 @@ public virtual IndentedStringBuilder AppendLines(string value, bool skipFinalNew
141141
return this;
142142
}
143143

144+
/// <summary>
145+
/// Appends a copy of the specified string if <paramref name="condition"/> is met.
146+
/// </summary>
147+
/// <param name="text">The string to append.</param>
148+
/// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrWhiteSpace method will be used.</param>
149+
public IndentedStringBuilder AppendIf(string text, Func<string, bool> condition = null)
150+
{
151+
var c = condition ?? (s => !string.IsNullOrEmpty(s));
152+
153+
if (c(text))
154+
Append(text);
155+
156+
return this;
157+
}
158+
159+
/// <summary>
160+
/// Appends a copy of the specified string if <paramref name="condition"/> is met.
161+
/// </summary>
162+
/// <param name="text">The string to append.</param>
163+
/// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrWhiteSpace method will be used.</param>
164+
public IndentedStringBuilder AppendIf(string text, bool condition)
165+
{
166+
if (condition)
167+
Append(text);
168+
169+
return this;
170+
}
171+
172+
/// <summary>
173+
/// Appends a copy of the specified string followed by the default line terminator if <paramref name="condition"/> is met.
174+
/// </summary>
175+
/// <param name="text">The string to append.</param>
176+
/// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrWhiteSpace method will be used.</param>
177+
public IndentedStringBuilder AppendLineIf(string text, Func<string, bool> condition = null)
178+
{
179+
var c = condition ?? (s => !string.IsNullOrEmpty(s));
180+
181+
if (c(text))
182+
AppendLine(text);
183+
184+
return this;
185+
}
186+
144187
/// <summary>
145188
/// Resets this builder ready to build a new string.
146189
/// </summary>

0 commit comments

Comments
 (0)