Skip to content

Commit

Permalink
Merge pull request #306 from loresoft/feature/services
Browse files Browse the repository at this point in the history
Feature/services
  • Loading branch information
pwelter34 authored Oct 12, 2023
2 parents 8b8a981 + aab58db commit 4a9f55e
Show file tree
Hide file tree
Showing 34 changed files with 681 additions and 269 deletions.
14 changes: 7 additions & 7 deletions src/FluentCommand.Caching/DistributedDataCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace FluentCommand.Caching;

/// <summary>
/// Distributed cache implemenation
/// Distributed data cache implementation
/// </summary>
/// <seealso cref="FluentCommand.IDataCache" />
public partial class DistributedDataCache : IDataCache
Expand Down Expand Up @@ -40,7 +40,7 @@ public DistributedDataCache(ILogger<DistributedDataCache> logger, IDistributedCa
/// <para>Success is true if the key was found; otherwise false</para>
/// <para>Value is the cache entry that is identified by key</para>
/// </returns>
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
/// <exception cref="System.ArgumentException">key cannot be null or empty. - key</exception>
public (bool Success, T Value) Get<T>(string key)
{
if (string.IsNullOrEmpty(key))
Expand Down Expand Up @@ -71,7 +71,7 @@ public DistributedDataCache(ILogger<DistributedDataCache> logger, IDistributedCa
/// <para>Success is true if the key was found; otherwise false</para>
/// <para>Value is the cache entry that is identified by key</para>
/// </returns>
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
/// <exception cref="System.ArgumentException">'key' cannot be null or empty. - key</exception>
public async Task<(bool Success, T Value)> GetAsync<T>(string key, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(key))
Expand Down Expand Up @@ -104,7 +104,7 @@ public DistributedDataCache(ILogger<DistributedDataCache> logger, IDistributedCa
/// <param name="value">The object to insert into cache.</param>
/// <param name="absoluteExpiration">The fixed date and time at which the cache entry will expire.</param>
/// <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>
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
/// <exception cref="System.ArgumentException">'key' cannot be null or empty. - key</exception>
/// <exception cref="System.ArgumentNullException">value</exception>
public void Set<T>(string key, T value, DateTimeOffset? absoluteExpiration = null, TimeSpan? slidingExpiration = null)
{
Expand Down Expand Up @@ -136,7 +136,7 @@ public void Set<T>(string key, T value, DateTimeOffset? absoluteExpiration = nul
/// <param name="absoluteExpiration">The fixed date and time at which the cache entry will expire.</param>
/// <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>
/// <param name="cancellationToken">The cancellation instruction.</param>
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
/// <exception cref="System.ArgumentException">'key' cannot be null or empty. - key</exception>
/// <exception cref="System.ArgumentNullException">value</exception>
public async Task SetAsync<T>(string key, T value, DateTimeOffset? absoluteExpiration = null, TimeSpan? slidingExpiration = null, CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -168,7 +168,7 @@ await _distributedCache
/// Removes the cache entry from the cache
/// </summary>
/// <param name="key">A unique identifier for the cache entry.</param>
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
/// <exception cref="System.ArgumentException">'key' cannot be null or empty. - key</exception>
public void Remove(string key)
{
if (string.IsNullOrEmpty(key))
Expand All @@ -184,7 +184,7 @@ public void Remove(string key)
/// </summary>
/// <param name="key">A unique identifier for the cache entry.</param>
/// <param name="cancellationToken">The cancellation instruction.</param>
/// <exception cref="System.ArgumentException">'{nameof(key)}' cannot be null or empty. - key</exception>
/// <exception cref="System.ArgumentException">'key' cannot be null or empty. - key</exception>
public async Task RemoveAsync(string key, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(key))
Expand Down
2 changes: 1 addition & 1 deletion src/FluentCommand.Caching/FluentCommand.Caching.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MessagePack" Version="2.5.124" />
<PackageReference Include="MessagePack" Version="2.5.129" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
</ItemGroup>
Expand Down
22 changes: 22 additions & 0 deletions src/FluentCommand.Caching/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using MessagePack;
using MessagePack.Resolvers;

using Microsoft.Extensions.DependencyInjection.Extensions;

namespace FluentCommand.Caching;

public static class ServiceCollectionExtensions
{
public static DataConfigurationBuilder AddDistributedDataCache(this DataConfigurationBuilder builder)
{
builder.AddService(sp =>
{
sp.TryAddSingleton(ContractlessStandardResolver.Options.WithCompression(MessagePackCompression.Lz4BlockArray));
sp.TryAddSingleton<IDistributedCacheSerializer, MessagePackCacheSerializer>();
});

builder.AddDataCache<DistributedDataCache>();

return builder;
}
}
4 changes: 3 additions & 1 deletion src/FluentCommand.Generators/DataReaderFactoryWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ private static void WriteEntityFactory(IndentedStringBuilder codeBuilder, Entity
.Append(aliasType)
.Append(" v_")
.Append(fieldName)
.AppendLine(" = default;");
.Append(" = default")
.AppendIf("!", _ => !entityProperty.PropertyType.EndsWith("?"))
.AppendLine(";");
}

codeBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<AnalyzerLanguage>cs</AnalyzerLanguage>
<AnalyzerRoslynVersion>4.3</AnalyzerRoslynVersion>
<LangVersion>latest</LangVersion>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<ItemGroup>
Expand Down
43 changes: 43 additions & 0 deletions src/FluentCommand.Generators/IndentedStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,49 @@ public virtual IndentedStringBuilder AppendLines(string value, bool skipFinalNew
return this;
}

/// <summary>
/// Appends a copy of the specified string if <paramref name="condition"/> is met.
/// </summary>
/// <param name="text">The string to append.</param>
/// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrWhiteSpace method will be used.</param>
public IndentedStringBuilder AppendIf(string text, Func<string, bool> condition = null)
{
var c = condition ?? (s => !string.IsNullOrEmpty(s));

if (c(text))
Append(text);

return this;
}

/// <summary>
/// Appends a copy of the specified string if <paramref name="condition"/> is met.
/// </summary>
/// <param name="text">The string to append.</param>
/// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrWhiteSpace method will be used.</param>
public IndentedStringBuilder AppendIf(string text, bool condition)
{
if (condition)
Append(text);

return this;
}

/// <summary>
/// Appends a copy of the specified string followed by the default line terminator if <paramref name="condition"/> is met.
/// </summary>
/// <param name="text">The string to append.</param>
/// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrWhiteSpace method will be used.</param>
public IndentedStringBuilder AppendLineIf(string text, Func<string, bool> condition = null)
{
var c = condition ?? (s => !string.IsNullOrEmpty(s));

if (c(text))
AppendLine(text);

return this;
}

/// <summary>
/// Resets this builder ready to build a new string.
/// </summary>
Expand Down
Loading

0 comments on commit 4a9f55e

Please sign in to comment.