BEFactoryBusinessLayer 1.0.12
See the version list below for details.
dotnet add package BEFactoryBusinessLayer --version 1.0.12
NuGet\Install-Package BEFactoryBusinessLayer -Version 1.0.12
<PackageReference Include="BEFactoryBusinessLayer" Version="1.0.12" />
paket add BEFactoryBusinessLayer --version 1.0.12
#r "nuget: BEFactoryBusinessLayer, 1.0.12"
// Install BEFactoryBusinessLayer as a Cake Addin #addin nuget:?package=BEFactoryBusinessLayer&version=1.0.12 // Install BEFactoryBusinessLayer as a Cake Tool #tool nuget:?package=BEFactoryBusinessLayer&version=1.0.12
Backend Factory
A library Back End for c# developer
History version
[v1.0.12] 2024-06-16
Added
- property ResponseContentBody on httpsClientHelper
When it is necessary not to deserialize a response from an httpClient call, it is possible to invoke the sednAsync method passing the object class as the type. In this case the http call payload will be returned. Here is an example:
protected httpsClientHelper _httpsClientHelper;
_httpsClientHelper.sendAsync<object>(
response.URLApiFeed,
response.ContentType,
response.httpMethod,
(exception) => loggerExtension.Trace(response.UrlADM, request.CorrelationId, Serilog.Events.LogEventLevel.Error, null, "Eccezione: {exception}", exception),
(nrretry) => loggerExtension.Trace(response.UrlADM, request.CorrelationId, Serilog.Events.LogEventLevel.Warning, null, "Numero di retry pari a : {nrretry}", nrretry)
).GetAwaiter().GetResult();
string payload = _httpsClientHelper.ResponseContentBody;
Topics
- BEFactoryBusinessLayer.Auth
- BEFactoryBusinessLayer.BackgroundJobs
- BEFactoryBusinessLayer.caching
- BEFactoryBusinessLayer.http
- BEFactoryBusinessLayer.Linq
- BEFactoryBusinessLayer.Logger
- BEFactoryBusinessLayer.resilience
- BEFactoryBusinessLayer.RMQ
- BEFactoryBusinessLayer.TaskHelper
- BEFactoryBusinessLayer.Validation
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
Also in case you need to use HttpClient to consume an http request you can use the HttpsClientHelper library by taking the IHttpClientFactory class. This is done via the piece of code written below:
var _httpClientFactory = scope.ServiceProvider.GetRequiredService<IHttpClientFactory>();
IactionParseRMQ iactionParseRMQ = scope.ServiceProvider.GetRequiredService<IactionParseRMQ>();
iactionParseRMQ._httpClientFactory = _httpClientFactory;
responseCheck = iactionParseRMQ.RunCommandOnConsuming(iactionParseRMQ._httpClientFactory, iactionParseRMQ._dbContextClient, feed, payload, CorrelationId, MessageType);
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 | Versions 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. |
-
net8.0
- AspNetCore.HealthChecks.SqlServer (>= 8.0.2)
- AspNetCore.HealthChecks.UI (>= 8.0.1)
- AspNetCore.HealthChecks.UI.Client (>= 8.0.1)
- AspNetCore.HealthChecks.UI.Core (>= 8.0.1)
- AspNetCore.HealthChecks.UI.Data (>= 8.0.1)
- AspNetCore.HealthChecks.UI.InMemory.Storage (>= 8.0.1)
- AspNetCore.HealthChecks.UI.SqlServer.Storage (>= 8.0.1)
- AspNetCore.HealthChecks.Uris (>= 8.0.1)
- EntityFramework (>= 6.4.4)
- Hangfire (>= 1.8.11)
- Hangfire.Console (>= 1.4.3)
- Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore (>= 8.0.6)
- Microsoft.EntityFrameworkCore (>= 8.0.6)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.6)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.6)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 8.0.5)
- Polly (>= 8.3.1)
- RabbitMQ.Client (>= 6.8.1)
- Serilog.AspNetCore (>= 8.0.1)
- Serilog.Sinks.Elasticsearch (>= 10.0.0)
- Serilog.Sinks.Email (>= 3.0.0)
- Serilog.Sinks.MSSqlServer (>= 6.6.0)
- Serilog.Sinks.Telegram (>= 0.2.1)
- StackExchange.Redis (>= 2.7.33)
- System.Data.SqlClient (>= 4.8.6)
- System.IdentityModel.Tokens.Jwt (>= 7.5.2)
- System.Threading.RateLimiting (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.