BaseLib.Core 2.1.0.4

dotnet add package BaseLib.Core --version 2.1.0.4                
NuGet\Install-Package BaseLib.Core -Version 2.1.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BaseLib.Core" Version="2.1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BaseLib.Core --version 2.1.0.4                
#r "nuget: BaseLib.Core, 2.1.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BaseLib.Core as a Cake Addin
#addin nuget:?package=BaseLib.Core&version=2.1.0.4

// Install BaseLib.Core as a Cake Tool
#tool nuget:?package=BaseLib.Core&version=2.1.0.4                

BaseLib.Core

Overview

BaseLib.Core is a foundational library for building backend services in .NET. It simplifies the creation of services by providing base classes that implement common patterns and functionalities.

BaseLib.Core services are platform-agnostic, meaning they can run in various environments, such as containers, Azure Functions, or AWS Lambdas.

Key Concepts

The Service Class

A service represents a single backend operation and follows a Request/Response pattern.

Request

Requests are derived from CoreRequestBase.

Example:

public class CheckoutRequest : CoreRequestBase
{
    public int CustomerId { get; set; }
    public string CustomerName { get; set; }
    public string IdentificationNumber { get; set; }
    public CreditCard? CreditCard { get; set; }
    public Product[] Items{ get; set; }
}

Response

Responses are derived from CoreResponseBase and contain a Succeeded property to indicate success.

Example:

public class CheckoutResponse : CoreResponseBase
{
    public long OrderId { get; set; }
}

Service Implementation

Services inherit from CoreServiceBase<TRequest,TResponse>, where TRequest and TResponse are your custom request and response types. The core logic is implemented in the RunAsync() method.

Example:

public class CheckoutService : CoreServiceBase<CheckoutRequest, CheckoutResponse>
{
    protected override async Task<CheckoutResponse> RunAsync()
    {
        // Implementation logic here...
        var order = await CreateOrderAsync(this.Request.CustomerId, this.Request.Items);
        return new CheckoutResponse { Succeeded = true, OrderId = order.Id };
    }
}

Reason codes

Responses include a ReasonCode, which consists of an integer value and a string description.

The ReasonCode can be assigned from Enum types. It maps the integer value from the enum's integer value and the description from the Description attribute, if present; otherwise, it uses the label of the enum value.

This approach offers a convenient way to handle Reason Codes as enums within the application.

Example:

enum EcommerceReasonCode
{
    [Description("Product is not available at this time")]
    NoItemsAvailable = 10448
}


public class CheckoutService : CoreServiceBase<CheckoutRequest, CheckoutResponse>
{
    protected override async Task<CheckoutResponse> RunAsync()
    {
        if (!CheckForAvailability(this.Request.Products))
        {
            return new CheckoutResponse
            {
                Succeeded = false,
                ReasonCode = EcommerceReasonCode.NoItemsAvailable
            };
        }
        // Implementation logic here...
    }
}

Events Support

The ICoreStatusEventSink interface provides support for event-driven choreography between services. This capability enables the asynchronous triggering of actions in response to events.

A typical implementation of ICoreStatusEventSink publishes the event to an external publish/subscribe messaging system, subscribers of the messaging system will react to events published by the service.

In the diagram below, a CheckoutService publish an event to a Topic on a messaging system. The subscribers of this Topic receive the events and subsequently execute the 'create order' and 'create invoice' services, respectively.

flowchart LR;
    s(CheckoutService) -- event --> Topic;
    Topic -- event --> s1-->CreateOrderService;
    Topic -- event -->s2-->CreateInvoiceService;

Service required to report events need to use the build in constructor passing the ICoreStatusEventSink.

Example:

public class CheckoutService : CoreServiceBase<CheckoutRequest, CheckoutResponse>
{

    // A Constructor with the eventsink
    public CheckoutService(ICoreStatusEventSink? eventsink)
        : base(eventSink: eventsink)
    {

    }

    // Implementation Logic here...
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on BaseLib.Core:

Package Downloads
FacturaE.Sdk

Package Description

BaseLib.Core.AmazonCloud

Package Description

BaseLib.Core.MySql

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0.4 633 5/22/2024
2.1.0.3 150 5/15/2024
2.1.0.2 683 1/16/2024
2.1.0.1 145 12/30/2023
2.1.0 460 12/28/2023
2.0.2 1,039 11/22/2023
2.0.1 237 11/21/2023
2.0.0 296 11/1/2023
1.1.0 176 10/16/2023
1.1.0-beta-004 3,327 11/22/2022
1.1.0-beta-003 490 11/16/2022
1.1.0-beta-002 212 11/15/2022
1.1.0-beta-001 178 11/3/2022
1.0.1 659 10/4/2022
1.0.0 728 10/3/2022
1.0.0-alpha-3 314 9/12/2022
1.0.0-alpha-2 387 8/22/2022
1.0.0-alpha-1 294 4/14/2022
1.0.0-alpha 201 3/31/2022