Skip to content

Commit

Permalink
Minor fixes/improves. (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun authored Oct 20, 2023
1 parent 660e7d5 commit a360dec
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Represents the **NuGet** versions.

## v3.4.1
- *Fixed:* The `IEfDb.With` fixed (as extension methods) to also support the `with` value being passed into the corresponding `Action<T>` to simplify usage (only a subset of common intrinsic types supported, both nullable and non-nullable overloads).
- *Fixed:* Missing `Result.CacheSet` and `Result.CacheRemove` extension methods added to `CoreEx.Results` to fully enable `IRequestCaching` in addition to existing `Result.CacheGetOrAddAsync`.

## v3.4.0
- *Enhancement:* Added `IEventSubscriberInstrumentation` (and related `EventSubscriberInstrumentationBase`) to enable `EventSubscriberBase.Instrumentation` monitoring of the subscriber as applicable.
- *Enhancement:* Previous `EventSubscriberInvoker` exception/error handling moved into individual subscribers for greater control; a new `ErrorHandler` added to encapsulate the consistent handling of the underlying exceptions/errors. This was internal and should have no impact.
Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.4.0</Version>
<Version>3.4.1</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/CoreEx.EntityFrameworkCore/EfDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void WithWildcard(string? with, Action<string> action)
/// <inheritdoc/>
public void With<T>(T with, Action action)
{
if (Comparer<T>.Default.Compare(with, default!) != 0 && Comparer<T>.Default.Compare(with, default!) != 0)
if (with is not null && Comparer<T>.Default.Compare(with, default!) != 0)
{
if (with is not string && with is System.Collections.IEnumerable ie && !ie.GetEnumerator().MoveNext())
return;
Expand Down
191 changes: 191 additions & 0 deletions src/CoreEx.EntityFrameworkCore/EfDbExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/CoreEx

using CoreEx.Entities;
using CoreEx.RefData;
using CoreEx.Results;

namespace CoreEx.EntityFrameworkCore
Expand Down Expand Up @@ -234,5 +235,195 @@ public static class EfDbExtensions
=> efDb.DeleteWithResultAsync<T, TModel>(new EfDbArgs(efDb.DbArgs), key, cancellationToken);

#endregion

#region With

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, string? with, Action<string> action) => efDb.With(with, () => action(with!));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, int? with, Action<int> action) => efDb.With(with, () => action(with!.Value));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, int with, Action<int> action) => efDb.With(with, () => action(with));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, short? with, Action<short> action) => efDb.With(with, () => action(with!.Value));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, short with, Action<short> action) => efDb.With(with, () => action(with));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, long? with, Action<long> action) => efDb.With(with, () => action(with!.Value));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, long with, Action<long> action) => efDb.With(with, () => action(with));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, decimal? with, Action<decimal> action) => efDb.With(with, () => action(with!.Value));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, decimal with, Action<decimal> action) => efDb.With(with, () => action(with));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, float? with, Action<float> action) => efDb.With(with, () => action(with!.Value));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, float with, Action<float> action) => efDb.With(with, () => action(with));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, double? with, Action<double> action) => efDb.With(with, () => action(with!.Value));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, double with, Action<double> action) => efDb.With(with, () => action(with));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, DateTime? with, Action<DateTime> action) => efDb.With(with, () => action(with!.Value));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, DateTime with, Action<DateTime> action) => efDb.With(with, () => action(with));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, TimeSpan? with, Action<TimeSpan> action) => efDb.With(with, () => action(with!.Value));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, TimeSpan with, Action<TimeSpan> action) => efDb.With(with, () => action(with));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, bool? with, Action<bool> action) => efDb.With(with, () => action(with!.Value));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, bool with, Action<bool> action) => efDb.With(with, () => action(with));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, char? with, Action<char> action) => efDb.With(with, () => action(with!.Value));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
/// </summary>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With(this IEfDb efDb, char with, Action<char> action) => efDb.With(with, () => action(with));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <typeparam name="TRef">The <see cref="IReferenceData"/> <see cref="Type"/>.</typeparam>
/// <param name="efDb"></param>
/// <param name="with"></param>
/// <param name="action"></param>
public static void With<TRef>(this IEfDb efDb, TRef? with, Action<TRef> action) where TRef : IReferenceData => efDb.With(with, () => action(with!));

/// <summary>
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
/// </summary>
/// <typeparam name="TRef">The <see cref="IReferenceData"/> <see cref="Type"/>.</typeparam>
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
/// <param name="with">The value with which to verify.</param>
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
public static void With<TRef>(this IEfDb efDb, ReferenceDataCodeList<TRef>? with, Action<ReferenceDataCodeList<TRef>> action) where TRef : class, IReferenceData, new() => efDb.With(with, () => action(with!));

#endregion
}
}
4 changes: 1 addition & 3 deletions src/CoreEx/Caching/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ To provide additional capabilities to cache data to improve runtime performance.

## Request cache

The [`IRequestCache`](./IRequestCache.cs) interface and corresponding [`RequestCache`](./RequestCache.cs) implementation are intended to provide generic short-lived request caching; for example, to reduce data chattiness within the context of a request scope.


The [`IRequestCache`](./IRequestCache.cs) interface and corresponding [`RequestCache`](./RequestCache.cs) implementation are intended to provide generic short-lived request caching; for example, to reduce data chattiness within the context of a request scope.
Loading

0 comments on commit a360dec

Please sign in to comment.