Coree.NETStandard
  • API
Show / Hide Table of Contents
  • Coree.NETStandard.Abstractions.DependencySingleton
    • DependencySingleton<T>
    • IDependencySingleton
  • Coree.NETStandard.Abstractions.FluentBase
    • FluentBase
    • IFluentBase
  • Coree.NETStandard.Abstractions.InitializationService
    • InitializationDependentServices
    • InitializationService
  • Coree.NETStandard.Abstractions.ServiceFactory
    • ServiceFactory<T>
  • Coree.NETStandard.Abstractions.ServiceFactoryEx
    • ServiceFactoryEx<T>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X, Y, Z>
    • ServiceFactoryEx<T, K>
    • ServiceFactoryEx<T, K, R>
    • ServiceFactoryEx<T, K, R, S>
    • ServiceFactoryEx<T, K, R, S, U>
    • ServiceFactoryEx<T, K, R, S, U, V>
    • ServiceFactoryEx<T, K, R, S, U, V, W>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X, Y>
  • Coree.NETStandard.Classes.AsyncEventCollection
    • AsyncEventCollection<T>
    • AsyncEventCollection<T>.CustomEventDelegate
  • Coree.NETStandard.Classes.CommonDistinguishedNameBuilder
    • CommonDistinguishedNameBuilder
    • DistinguishedName
  • Coree.NETStandard.Classes.Criteria
    • CriteriaComparisonMethod
    • CriteriaEnumerableExtensions
    • CriteriaExpressionBuilder
    • CriteriaItem<TValue>
    • CriteriaItems
    • CriteriaOperator
    • CriteriaQueryableExtensions
  • Coree.NETStandard.Classes.HttpRequestService
    • ContentComposer
    • HttpRequestHeadersExtensions
    • HttpRequestService
    • HttpRequestServiceHandler
    • HttpRequestServiceUriExtensions
    • ServiceCollectionExtensions
    • TransactionRecord
  • Coree.NETStandard.Classes.Scheduler
    • Scheduler
    • Scheduler.TickerEventArgs
    • Scheduler.TickerEventDelegate
  • Coree.NETStandard.Classes.ThreadSafeCollection
    • ThreadSafeCollection<T>
  • Coree.NETStandard.Classes.ThreadSafeValue
    • ThreadSafeValue<T>
  • Coree.NETStandard.Classes.TimeOfDay
    • TimeOfDay
  • Coree.NETStandard.Extensions.Collections.Enumerable
    • CollectionsEnumerableExtensions
  • Coree.NETStandard.Extensions.Collections.List
    • CollectionsListExtensions
  • Coree.NETStandard.Extensions.Conversions.ByteArray
    • ConversionsByteArrayExtensions
  • Coree.NETStandard.Extensions.Conversions.HostApplicationBuilder
    • ConversionsHostApplicationBuilderExtensions
  • Coree.NETStandard.Extensions.Conversions.String
    • ConversionsStringExtensions
    • Encodings
  • Coree.NETStandard.Extensions.Conversions.Stringbuilder
    • ConversionsStringbuilderExtension
  • Coree.NETStandard.Extensions.Enums
    • EnumExtensions
  • Coree.NETStandard.Extensions.Http.HttpHeader
    • HttpHeadersExtensions
  • Coree.NETStandard.Extensions.Primitives.Bool
    • PrimitivesBoolExtensions
  • Coree.NETStandard.Extensions.Reflection.ServiceProvider
    • ReflectionServiceProviderExtensions
  • Coree.NETStandard.Extensions.ServiceCollection
    • ServiceCollectionExtensions
  • Coree.NETStandard.Extensions.Threading.CancellationToken
    • ThreadingCancellationTokenExtensions
  • Coree.NETStandard.Extensions.Utilities
    • DateTimeExtensions
  • Coree.NETStandard.Extensions.Validations.String
    • ValidationsStringExtensions
  • Coree.NETStandard.HostedServicesCollection
    • HostedServicesCollectionConfig<T>
    • IHostedServicesCollectionConfig<T>
    • ServiceCollectionExtensions
    • ServiceProviderExtensions
  • Coree.NETStandard.Serilog
    • ConditionalLevelSink
    • CustomTheme
    • LoggerSinkConfigurationExtensions
    • OutputTemplates
    • ServiceCollectionExtensions
    • SourceContextShortEnricher
  • Coree.NETStandard.Services.DebugManagement
    • DebugService
    • IDebugService
  • Coree.NETStandard.Services.DirectoryOperationsManagement
    • DirectoryOperationsService
    • IDirectoryOperationsService
  • Coree.NETStandard.Services.FileManagement
    • FileService
    • IFileService
  • Coree.NETStandard.Services.FileOperationsManagement
    • FileOperationsService
    • FileOperationsService.FileSystemEntry
    • FileOperationsService.FileSystemInformation
    • FileOperationsService.VerifiedCopyStatus
    • IFileOperationsService
  • Coree.NETStandard.Services.HashManagement
    • HashService
    • IHashService
  • Coree.NETStandard.Services.NetworkManagement
    • INetworkService
    • NetworkService
    • NetworkService.IpAdressInformation
    • NetworkService.NetworkInterfaceDetail
  • Coree.NETStandard.Services.ProcessManagement
    • IProcessService
    • ProcessRunExitCodeState
    • ProcessRunResult
    • ProcessService
  • Coree.NETStandard.Services.RuntimeInsightsManagement
    • IRuntimeInsightsService
    • RuntimeInsightsService
  • Coree.NETStandard.SpectreConsole
    • CommandAppExtensions
    • HostBuilderExtensions
    • ServiceCollectionExtensions
    • SpectreConsoleHostedService
    • SpectreConsoleHostedService.ExitCode
    • SpectreConsoleTypeRegistrar
    • SpectreConsoleTypeResolver
  • Coree.NETStandard.UnderConstruction
    • DbContextExtensions
    • HttpClientStatic
    • HttpClientStatic.HttpClientResponse
    • HttpClientStatic.XRate
    • HttpClientStatic.XRateGroup
    • HttpClientStatic.XRateItem
    • IScheduleProvider
    • IntervalScheduleProvider
    • LimitedHistory<T>
    • ScheduleCombiner
    • Scheduler
    • Scheduler.TickerEventArgs
    • Scheduler.TickerEventDelegate
    • Scheduler2
    • Scheduler2.TickerEventArgs
    • Scheduler2.TickerEventDelegate
    • Scheduler3
    • Scheduler3.TickerEventArgs
    • Scheduler3.TickerEventDelegate
    • SqlliteMemoryContext
    • SqlliteMemoryContext.UserDataDto
    • TimedEntry<T>
    • Timing
    • Timing.Ticker
    • Timing.Ticker.TickerEventArgs
    • Timing.TickerSync
    • WeekDayAtScheduleProvider
  • Coree.NETStandard.Utilities
    • EventSubscription
    • MainContext

Interface IFluentBase

Serves as a foundational class for fluent interface pattern error handling, enabling mechanisms for both error accumulation and immediate exception throwing, alongside optional continuation after encountering validation errors. This abstract class standardizes error management for classes utilizing fluent interfaces.

Namespace: Coree.NETStandard.Abstractions.FluentBase
Assembly: Coree.NETStandard.dll
Syntax
public interface IFluentBase
Remarks

Implements IFluentBase, offering:

  • Error accumulation during operations.
  • Conditional continuation of operations post-errors.
  • Flexible toggling between immediate exception throwing or error accumulation, adapting to various error handling strategies.
Examples

Illustrates the use of FluentBase with a concrete Product class and an extension method for price adjustment with comprehensive error handling:

public abstract class FluentBase : IFluentBase
{
    private bool throwOnError = true;
    public List<Exception> ValidationErrors { get; private set; } = new List<Exception>();
    public bool IsValid => !ValidationErrors.Any();
    public bool ContinueOnValidationError { get; private set; } = false;

    public void AddValidationError(string message, Exception innerException)
    {
        ValidationErrors.Add(new Exception(message, innerException));
        if (throwOnError)
        {
            throw innerException;
        }
    }

    public IFluentBase EnableThrowOnError()
    {
        throwOnError = true;
        ContinueOnValidationError = false;
        return this;
    }

    public IFluentBase DisableThrowOnError(bool continueOnValidationError = false)
    {
        throwOnError = false;
        ContinueOnValidationError = continueOnValidationError;
        return this;
    }
}

// Simplified Product class inheriting FluentBase
public class Product : FluentBase
{
    public string Name { get; set; }
    public decimal Price { get; set; }
}

// Extension method for Product
public static class ProductExtensions
{
    public static Product AdjustPrice(this Product product, decimal adjustment)
    {
        if (!product.IsValid && !product.ContinueOnValidationError) return product;

        try
        {
            var newPrice = product.Price + adjustment;
            if (newPrice < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(adjustment), "Adjustment results in a negative price.");
            }
            product.Price = newPrice;
        }
        catch (Exception ex)
        {
            product.AddValidationError($"Error adjusting price by {adjustment}: {ex.Message}", ex);
        }

        return product;
    }
}

Properties

| Edit this page View Source

ContinueOnValidationError

Indicates whether operations should continue after a validation error has occurred.

Declaration
bool ContinueOnValidationError { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsValid

Indicates whether the current object is in a valid state.

Declaration
bool IsValid { get; }
Property Value
Type Description
bool
| Edit this page View Source

ValidationErrors

A collection of exceptions that have been accumulated during operations.

Declaration
List<Exception> ValidationErrors { get; }
Property Value
Type Description
List<Exception>

Methods

| Edit this page View Source

AddValidationError(string, Exception)

Adds a validation error to the collection with a custom message and the exception that occurred.

Declaration
void AddValidationError(string message, Exception innerException)
Parameters
Type Name Description
string message

The error message.

Exception innerException

The exception that occurred during validation.

| Edit this page View Source

DisableThrowOnError(bool)

Disables the behavior of throwing exceptions immediately, allowing operations to accumulate validation errors. Optionally allows continuation after validation errors based on the continueOnValidationError parameter.

Declaration
IFluentBase DisableThrowOnError(bool continueOnValidationError = false)
Parameters
Type Name Description
bool continueOnValidationError

Determines whether to continue operations after a validation error has occurred.

Returns
Type Description
IFluentBase

The current instance of IFluentBase.

| Edit this page View Source

EnableThrowOnError()

Enables the behavior to throw exceptions immediately when a validation error occurs. Resets ContinueOnValidationError to false.

Declaration
IFluentBase EnableThrowOnError()
Returns
Type Description
IFluentBase

The current instance of IFluentBase.

  • Edit this page
  • View Source
In this article
Back to top