BEFactoryBusinessLayer 1.0.9

There is a newer version of this package available.
See the version list below for details.
dotnet add package BEFactoryBusinessLayer --version 1.0.9                
NuGet\Install-Package BEFactoryBusinessLayer -Version 1.0.9                
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="BEFactoryBusinessLayer" Version="1.0.9" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BEFactoryBusinessLayer --version 1.0.9                
#r "nuget: BEFactoryBusinessLayer, 1.0.9"                
#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 BEFactoryBusinessLayer as a Cake Addin
#addin nuget:?package=BEFactoryBusinessLayer&version=1.0.9

// Install BEFactoryBusinessLayer as a Cake Tool
#tool nuget:?package=BEFactoryBusinessLayer&version=1.0.9                

Backend Factory

A complete library for c# developer

Topics

Auth

Library for authorize to get a controller

BackgroundJobs

Library for manage Hangfire

caching

This project is used to manage RabbitMQ using more channels

Http

Use Http Client with several scenario

Logger

Use Serilog with several sinks and customizations

Resilience

very useful Polly client features

RMQ

Use RabbitMQ to admin with more channel and isolate business logic to consume it

Configuration

  • AppSettings.json:
  "rabbitMQChannelsOptions": [
    {
      "Name": "FirstName",
      "IdFeed": 1,
      "RabbitEndPoint": {
        "HostName": "Your_Endpoint",
        "UserName": "Your_UserName",
        "Password": "Your_Password",
        "ClientProvidedName": "Your_ClientName",
        "VirtualHost": "Your_Virtual",
        "QueueName": "Your_QueueName_",
        "RejectMessageWithError": true
      }
    },
    {
      "Name": "SecondName",
      "IdFeed": 2,
      "RabbitEndPoint": {
        "HostName": "Your_Endpoint",
        "UserName": "Your_UserName",
        "Password": "Your_Password",
        "ClientProvidedName": "Your_ClientName",
        "VirtualHost": "Your_Virtual",
        "QueueName": "Your_QueueName_",
        "RejectMessageWithError": true
      }
    }
  ]    
  • Name : used to identify the name of the queue to manage

  • IdFeed : Id of channel

  • RabbitEndPoint:HostName : Url of RMQ producer

  • RabbitEndPoint:UserName : Username of RMQ producer

  • RabbitEndPoint:Password : Password of RMQ producer

  • RabbitEndPoint:ClientProvidedName : ClientProvidedName of RMQ producer

  • RabbitEndPoint:VirtualHost : VirtualHost of RMQ producer

  • RabbitEndPoint:QueueName : QueueName of RMQ producer

  • RabbitEndPoint:RejectMessageWithError : boolean value, when true the response is inserted into the unacknowledged message queue

  • program.cs:

//To load Configuration
builder.Services.AddOptions();
var rabbitMQChannelsOptions = builder.Configuration.GetSection("rabbitMQChannelsOptions");
builder.Services.Configure<List<RabbitMQChannelsOptions>>(rabbitMQChannelsOptions);
List<RabbitMQChannelsOptions> channelSettings = builder.Configuration.GetSection("rabbitMQChannelsOptions").Get<List<RabbitMQChannelsOptions>>();
/*
   Inject RabbitMQ service:
   This add delegate to run youir businesseLogic, in this case i add 
   Func<DbContext, RabbitMQChannelsOptions, string, string, string, Response>
   Where : 
   - - DbContext is your custom DbContext to manage SQL Server
   - - RabbitMQChannelsOptions is option load before
   - - payload is content sent from RMQ
   - - CorrelationId is value sent from header RMQ
   - - MessageType where defined is a string property set on property RMQ to identify your action

   addhostedrabbitService inject a AddHostedService to manage queue
*/
builder.Services.addhostedrabbitService<ApplicationDbContext>(
   (dbcontext, channelOptions, payload, CorrelationId, MessageType) => new Feedfactory(channelSettings).ConsumeMessage((ApplicationDbContext)dbcontext, channelOptions, payload, CorrelationId, MessageType)
);

In this case all the business logic is performed by the ConsumeMessage method of the Feedfactory class which reads all the queues configured on appSettings. Note that a custom one named ApplicationDbContext is passed as DbContext Property how to publish message with these properties

TaskHelper

Some example to use Task async

Validation

To use a response with some Pattern Design

-

    • Program.cs: Config host and inject services.
#region RabbitMQ
builder.Services.AddOptions();
var rabbitMQChannelsOptions = builder.Configuration.GetSection("rabbitMQChannelsOptions");
builder.Services.Configure<List<RabbitMQChannelsOptions>>(rabbitMQChannelsOptions);
List<RabbitMQChannelsOptions> channelSettings = builder.Configuration.GetSection("rabbitMQChannelsOptions").Get<List<RabbitMQChannelsOptions>>();

builder.Services.AddDbContext<ApplicationDbContext>(options => {
    options.UseSqlServer(builder.Configuration.GetConnectionString("default"),
        sqlServerOptionsAction: sqloptions => sqloptions.EnableRetryOnFailure());
}, ServiceLifetime.Scoped);

builder.Services.addhostedrabbitService<ApplicationDbContext>(
    (dbcontext, channelOptions, payload, CorrelationId, MessageType) => new Feedfactory(channelSettings).ConsumeMessage((feedDbContext)dbcontext, channelOptions, payload, CorrelationId, MessageType)
);
#endregion

For every message consumed by RMQ youcan use lambda like : 
	(dbcontext, channelOptions, payload, CorrelationId, MessageType) => new Feedfactory(channelSettings).ConsumeMessage((feedDbContext)dbcontext, channelOptions, payload, CorrelationId, MessageType)
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.18 112 7/30/2024
1.0.17 81 7/19/2024
1.0.16 114 6/28/2024
1.0.15 114 6/25/2024
1.0.14 109 6/21/2024
1.0.13 114 6/20/2024
1.0.12 112 6/16/2024
1.0.11 102 6/16/2024
1.0.10 108 6/15/2024
1.0.9 97 6/12/2024
1.0.8 104 6/9/2024
1.0.7 117 6/6/2024
1.0.6 99 6/4/2024