BaseLib.Core
2.1.0.3
See the version list below for details.
dotnet add package BaseLib.Core --version 2.1.0.3
NuGet\Install-Package BaseLib.Core -Version 2.1.0.3
<PackageReference Include="BaseLib.Core" Version="2.1.0.3" />
paket add BaseLib.Core --version 2.1.0.3
#r "nuget: BaseLib.Core, 2.1.0.3"
// Install BaseLib.Core as a Cake Addin #addin nuget:?package=BaseLib.Core&version=2.1.0.3 // Install BaseLib.Core as a Cake Tool #tool nuget:?package=BaseLib.Core&version=2.1.0.3
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 | Versions 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. |
-
net6.0
- FluentValidation (>= 10.4.0)
- MimeKit (>= 4.5.0)
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 | 724 | 5/22/2024 |
2.1.0.3 | 157 | 5/15/2024 |
2.1.0.2 | 696 | 1/16/2024 |
2.1.0.1 | 149 | 12/30/2023 |
2.1.0 | 464 | 12/28/2023 |
2.0.2 | 1,043 | 11/22/2023 |
2.0.1 | 241 | 11/21/2023 |
2.0.0 | 300 | 11/1/2023 |
1.1.0 | 180 | 10/16/2023 |
1.1.0-beta-004 | 3,330 | 11/22/2022 |
1.1.0-beta-003 | 492 | 11/16/2022 |
1.1.0-beta-002 | 214 | 11/15/2022 |
1.1.0-beta-001 | 180 | 11/3/2022 |
1.0.1 | 663 | 10/4/2022 |
1.0.0 | 732 | 10/3/2022 |
1.0.0-alpha-3 | 316 | 9/12/2022 |
1.0.0-alpha-2 | 389 | 8/22/2022 |
1.0.0-alpha-1 | 296 | 4/14/2022 |
1.0.0-alpha | 203 | 3/31/2022 |