Skip to content

Commit a360dec

Browse files
authored
Minor fixes/improves. (#77)
1 parent 660e7d5 commit a360dec

File tree

7 files changed

+355
-15
lines changed

7 files changed

+355
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Represents the **NuGet** versions.
44

5+
## v3.4.1
6+
- *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).
7+
- *Fixed:* Missing `Result.CacheSet` and `Result.CacheRemove` extension methods added to `CoreEx.Results` to fully enable `IRequestCaching` in addition to existing `Result.CacheGetOrAddAsync`.
8+
59
## v3.4.0
610
- *Enhancement:* Added `IEventSubscriberInstrumentation` (and related `EventSubscriberInstrumentationBase`) to enable `EventSubscriberBase.Instrumentation` monitoring of the subscriber as applicable.
711
- *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.

Common.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>3.4.0</Version>
3+
<Version>3.4.1</Version>
44
<LangVersion>preview</LangVersion>
55
<Authors>Avanade</Authors>
66
<Company>Avanade</Company>

src/CoreEx.EntityFrameworkCore/EfDb.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public void WithWildcard(string? with, Action<string> action)
243243
/// <inheritdoc/>
244244
public void With<T>(T with, Action action)
245245
{
246-
if (Comparer<T>.Default.Compare(with, default!) != 0 && Comparer<T>.Default.Compare(with, default!) != 0)
246+
if (with is not null && Comparer<T>.Default.Compare(with, default!) != 0)
247247
{
248248
if (with is not string && with is System.Collections.IEnumerable ie && !ie.GetEnumerator().MoveNext())
249249
return;

src/CoreEx.EntityFrameworkCore/EfDbExtensions.cs

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/CoreEx
22

33
using CoreEx.Entities;
4+
using CoreEx.RefData;
45
using CoreEx.Results;
56

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

236237
#endregion
238+
239+
#region With
240+
241+
/// <summary>
242+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
243+
/// </summary>
244+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
245+
/// <param name="with">The value with which to verify.</param>
246+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
247+
public static void With(this IEfDb efDb, string? with, Action<string> action) => efDb.With(with, () => action(with!));
248+
249+
/// <summary>
250+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
251+
/// </summary>
252+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
253+
/// <param name="with">The value with which to verify.</param>
254+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
255+
public static void With(this IEfDb efDb, int? with, Action<int> action) => efDb.With(with, () => action(with!.Value));
256+
257+
/// <summary>
258+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
259+
/// </summary>
260+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
261+
/// <param name="with">The value with which to verify.</param>
262+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
263+
public static void With(this IEfDb efDb, int with, Action<int> action) => efDb.With(with, () => action(with));
264+
265+
/// <summary>
266+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
267+
/// </summary>
268+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
269+
/// <param name="with">The value with which to verify.</param>
270+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
271+
public static void With(this IEfDb efDb, short? with, Action<short> action) => efDb.With(with, () => action(with!.Value));
272+
273+
/// <summary>
274+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
275+
/// </summary>
276+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
277+
/// <param name="with">The value with which to verify.</param>
278+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
279+
public static void With(this IEfDb efDb, short with, Action<short> action) => efDb.With(with, () => action(with));
280+
281+
/// <summary>
282+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
283+
/// </summary>
284+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
285+
/// <param name="with">The value with which to verify.</param>
286+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
287+
public static void With(this IEfDb efDb, long? with, Action<long> action) => efDb.With(with, () => action(with!.Value));
288+
289+
/// <summary>
290+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
291+
/// </summary>
292+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
293+
/// <param name="with">The value with which to verify.</param>
294+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
295+
public static void With(this IEfDb efDb, long with, Action<long> action) => efDb.With(with, () => action(with));
296+
297+
/// <summary>
298+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
299+
/// </summary>
300+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
301+
/// <param name="with">The value with which to verify.</param>
302+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
303+
public static void With(this IEfDb efDb, decimal? with, Action<decimal> action) => efDb.With(with, () => action(with!.Value));
304+
305+
/// <summary>
306+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
307+
/// </summary>
308+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
309+
/// <param name="with">The value with which to verify.</param>
310+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
311+
public static void With(this IEfDb efDb, decimal with, Action<decimal> action) => efDb.With(with, () => action(with));
312+
313+
/// <summary>
314+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
315+
/// </summary>
316+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
317+
/// <param name="with">The value with which to verify.</param>
318+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
319+
public static void With(this IEfDb efDb, float? with, Action<float> action) => efDb.With(with, () => action(with!.Value));
320+
321+
/// <summary>
322+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
323+
/// </summary>
324+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
325+
/// <param name="with">The value with which to verify.</param>
326+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
327+
public static void With(this IEfDb efDb, float with, Action<float> action) => efDb.With(with, () => action(with));
328+
329+
/// <summary>
330+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
331+
/// </summary>
332+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
333+
/// <param name="with">The value with which to verify.</param>
334+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
335+
public static void With(this IEfDb efDb, double? with, Action<double> action) => efDb.With(with, () => action(with!.Value));
336+
337+
/// <summary>
338+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
339+
/// </summary>
340+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
341+
/// <param name="with">The value with which to verify.</param>
342+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
343+
public static void With(this IEfDb efDb, double with, Action<double> action) => efDb.With(with, () => action(with));
344+
345+
/// <summary>
346+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
347+
/// </summary>
348+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
349+
/// <param name="with">The value with which to verify.</param>
350+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
351+
public static void With(this IEfDb efDb, DateTime? with, Action<DateTime> action) => efDb.With(with, () => action(with!.Value));
352+
353+
/// <summary>
354+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
355+
/// </summary>
356+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
357+
/// <param name="with">The value with which to verify.</param>
358+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
359+
public static void With(this IEfDb efDb, DateTime with, Action<DateTime> action) => efDb.With(with, () => action(with));
360+
361+
/// <summary>
362+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
363+
/// </summary>
364+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
365+
/// <param name="with">The value with which to verify.</param>
366+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
367+
public static void With(this IEfDb efDb, TimeSpan? with, Action<TimeSpan> action) => efDb.With(with, () => action(with!.Value));
368+
369+
/// <summary>
370+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
371+
/// </summary>
372+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
373+
/// <param name="with">The value with which to verify.</param>
374+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
375+
public static void With(this IEfDb efDb, TimeSpan with, Action<TimeSpan> action) => efDb.With(with, () => action(with));
376+
377+
/// <summary>
378+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
379+
/// </summary>
380+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
381+
/// <param name="with">The value with which to verify.</param>
382+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
383+
public static void With(this IEfDb efDb, bool? with, Action<bool> action) => efDb.With(with, () => action(with!.Value));
384+
385+
/// <summary>
386+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
387+
/// </summary>
388+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
389+
/// <param name="with">The value with which to verify.</param>
390+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
391+
public static void With(this IEfDb efDb, bool with, Action<bool> action) => efDb.With(with, () => action(with));
392+
393+
/// <summary>
394+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
395+
/// </summary>
396+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
397+
/// <param name="with">The value with which to verify.</param>
398+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
399+
public static void With(this IEfDb efDb, char? with, Action<char> action) => efDb.With(with, () => action(with!.Value));
400+
401+
/// <summary>
402+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>default</c>.
403+
/// </summary>
404+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
405+
/// <param name="with">The value with which to verify.</param>
406+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
407+
public static void With(this IEfDb efDb, char with, Action<char> action) => efDb.With(with, () => action(with));
408+
409+
/// <summary>
410+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
411+
/// </summary>
412+
/// <typeparam name="TRef">The <see cref="IReferenceData"/> <see cref="Type"/>.</typeparam>
413+
/// <param name="efDb"></param>
414+
/// <param name="with"></param>
415+
/// <param name="action"></param>
416+
public static void With<TRef>(this IEfDb efDb, TRef? with, Action<TRef> action) where TRef : IReferenceData => efDb.With(with, () => action(with!));
417+
418+
/// <summary>
419+
/// Invokes the <paramref name="action"/> when the <paramref name="with"/> is not <c>null</c>.
420+
/// </summary>
421+
/// <typeparam name="TRef">The <see cref="IReferenceData"/> <see cref="Type"/>.</typeparam>
422+
/// <param name="efDb">The <see cref="IEfDb"/>.</param>
423+
/// <param name="with">The value with which to verify.</param>
424+
/// <param name="action">The <see cref="Action"/> to invoke when there is a valid <paramref name="with"/> value.</param>
425+
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!));
426+
427+
#endregion
237428
}
238429
}

src/CoreEx/Caching/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ To provide additional capabilities to cache data to improve runtime performance.
1212

1313
## Request cache
1414

15-
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.
16-
17-
15+
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.

0 commit comments

Comments
 (0)