Encamina.Enmarcha.Services.Abstractions
8.1.6-preview-05
See the version list below for details.
dotnet add package Encamina.Enmarcha.Services.Abstractions --version 8.1.6-preview-05
NuGet\Install-Package Encamina.Enmarcha.Services.Abstractions -Version 8.1.6-preview-05
<PackageReference Include="Encamina.Enmarcha.Services.Abstractions" Version="8.1.6-preview-05" />
paket add Encamina.Enmarcha.Services.Abstractions --version 8.1.6-preview-05
#r "nuget: Encamina.Enmarcha.Services.Abstractions, 8.1.6-preview-05"
// Install Encamina.Enmarcha.Services.Abstractions as a Cake Addin #addin nuget:?package=Encamina.Enmarcha.Services.Abstractions&version=8.1.6-preview-05&prerelease // Install Encamina.Enmarcha.Services.Abstractions as a Cake Tool #tool nuget:?package=Encamina.Enmarcha.Services.Abstractions&version=8.1.6-preview-05&prerelease
Services - Abstractions
Services Abstractions is a project that provides useful abstractions for your services. It contains classes and interfaces so that you can create an execution context and gather information that you can later consume from your services.
Setup
Nuget package
First, install NuGet. Then, install Encamina.Enmarcha.Services.Abstractions from the package manager console:
PM> Install-Package Encamina.Enmarcha.Services.Abstractions
.NET CLI:
Install .NET CLI. Next, install Encamina.Enmarcha.Services.Abstractions from the .NET CLI:
dotnet add package Encamina.Enmarcha.Services.Abstractions
How to use
ExecutionContext/ExecutionContextTemplate
This is a set of base classes and interfaces that are useful for creating an execution context that aggregates information and can be consumed from any point in your application. This way, the information from the execution context is centralized in a single point.
- IExecutionContext is an interface that represents a basic execution.
- ExecutionContext is a base class for basic execution contexts.
- IExecutionContext<T> is an interface that represents a basic execution context for a specific type.
- ExecutionContext<T> is a base class for basic execution contexts for a specific type.
- IExecutionContextTemplate is an interface that represents the template that can be used to create or configure an
IExecutionContext
. - ExecutionContextTemplate is a base class for a template that can be used to create or configure an
IExecutionContext
.
To illustrate the usage, let's create an execution context that can be used in a Web API. In addition to the basic information, a new field called FooInformation
will be added. Some of the constants referenced in the following code block belong to the NuGet package Encamina.Enmarcha.Net.Http.
public interface IApiExecutionContextTemplate : IExecutionContextTemplate
{
string FooInformation { get; init; }
}
public class ApiExecutionContextTemplate: ExecutionContextTemplate, IApiExecutionContextTemplate
{
public ApiExecutionContextTemplate(IHttpContextAccessor httpContextAccessor)
{
var httpContext = httpContextAccessor.HttpContext;
CorrelationCallId = httpContext.ReadValueFromRequestHeader(Constants.HttpHeaders.CorrelationCallId, Guid.NewGuid().ToString());
CorrelationId = httpContext.ReadValueFromRequestHeader(Constants.HttpHeaders.CorrelationId, httpContext.TraceIdentifier);
CancellationToken = httpContext.RequestAborted;
CultureInfo = CultureInfo.CurrentCulture;
FooInformation = "Bar";
}
public string FooInformation { get; init; }
}
public interface IApiExecutionContext<T> : IApiExecutionContextTemplate, IExecutionContext<T>
where T : class
{
}
public class ApiExecutionContext<T> : ExecutionContext<T>, IApiExecutionContext<T> where T : class
{
public ApiExecutionContext(IApiExecutionContextTemplate template, ILogger<T> logger) : base(template, logger)
{
FooInformation = template.FooInformation;
}
public string FooInformation { get; init; }
}
In the code above, ApiExecutionContextTemplate
is created to contain the required information. Subsequently, this template is received in ApiExecutionContext, which will be the class passed to the controllers.
The next step is, at some point in the Program.cs or a similar entry point file in your project, to add the following code to configure the IoC Container.
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
// ...
});
// ...
builder.Services.AddLogging();
// ...
builder.Services.AddExecutionContext(
typeof(IApiExecutionContext<>),
typeof(ApiExecutionContext<>),
typeof(IApiExecutionContextTemplate),
typeof(ApiExecutionContextTemplate));
// ...
The AddExecutionContext
method is responsible for validating and configuring everything necessary as Scoped
. Now, everything is set up to receive the execution context in a controller.
[ApiController]
[Route(@"api/[controller]")]
public class MyCustomController : Controller
{
private readonly IApiExecutionContext<MyCustomController> executionContext;
public MyCustomController(IApiExecutionContext<MyCustomController> executionContext)
{
this.executionContext = executionContext;
}
[HttpGet("say_hello")]
[ActionName(nameof(SayHello))]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> SayHello(CancellationToken cancellationToken)
{
// ...
// Now, we can access executionContext, and we have all the information related to this execution context.
executionContext.Logger.LogInformation($"Logger from {nameof(SayHello)} method with {executionContext.CorrelationId} and {executionContext.CultureInfo.TwoLetterISOLanguageName}");
executionContext.Logger.LogInformation($"FooInformation is {executionContext.FooInformation}");
// ...
return Ok("Hello");
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- CommunityToolkit.Diagnostics (>= 8.2.2)
- Encamina.Enmarcha.Core (>= 8.1.6-preview-05)
- Encamina.Enmarcha.Entities.Abstractions (>= 8.1.6-preview-05)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
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 |
---|---|---|
8.2.0 | 67 | 10/22/2024 |
8.2.0-preview-01-m01 | 85 | 9/17/2024 |
8.1.9-preview-03 | 58 | 11/19/2024 |
8.1.9-preview-02 | 55 | 10/22/2024 |
8.1.9-preview-01 | 65 | 10/4/2024 |
8.1.8 | 85 | 9/23/2024 |
8.1.8-preview-07 | 71 | 9/12/2024 |
8.1.8-preview-06 | 89 | 9/11/2024 |
8.1.8-preview-05 | 91 | 9/10/2024 |
8.1.8-preview-04 | 99 | 8/16/2024 |
8.1.8-preview-03 | 97 | 8/13/2024 |
8.1.8-preview-02 | 93 | 8/13/2024 |
8.1.8-preview-01 | 91 | 8/12/2024 |
8.1.7 | 94 | 8/7/2024 |
8.1.7-preview-09 | 95 | 7/3/2024 |
8.1.7-preview-08 | 86 | 7/2/2024 |
8.1.7-preview-07 | 75 | 6/10/2024 |
8.1.7-preview-06 | 75 | 6/10/2024 |
8.1.7-preview-05 | 83 | 6/6/2024 |
8.1.7-preview-04 | 83 | 6/6/2024 |
8.1.7-preview-03 | 94 | 5/24/2024 |
8.1.7-preview-02 | 97 | 5/10/2024 |
8.1.7-preview-01 | 92 | 5/8/2024 |
8.1.6 | 1,227 | 5/7/2024 |
8.1.6-preview-08 | 69 | 5/2/2024 |
8.1.6-preview-07 | 96 | 4/29/2024 |
8.1.6-preview-06 | 99 | 4/26/2024 |
8.1.6-preview-05 | 97 | 4/24/2024 |
8.1.6-preview-04 | 88 | 4/22/2024 |
8.1.6-preview-03 | 99 | 4/22/2024 |
8.1.6-preview-02 | 87 | 4/17/2024 |
8.1.6-preview-01 | 174 | 4/15/2024 |
8.1.5 | 111 | 4/15/2024 |
8.1.5-preview-15 | 93 | 4/10/2024 |
8.1.5-preview-14 | 102 | 3/20/2024 |
8.1.5-preview-13 | 82 | 3/18/2024 |
8.1.5-preview-12 | 108 | 3/13/2024 |
8.1.5-preview-11 | 82 | 3/13/2024 |
8.1.5-preview-10 | 79 | 3/13/2024 |
8.1.5-preview-09 | 88 | 3/12/2024 |
8.1.5-preview-08 | 100 | 3/12/2024 |
8.1.5-preview-07 | 73 | 3/8/2024 |
8.1.5-preview-06 | 74 | 3/8/2024 |
8.1.5-preview-05 | 72 | 3/7/2024 |
8.1.5-preview-04 | 81 | 3/7/2024 |
8.1.5-preview-03 | 101 | 3/7/2024 |
8.1.5-preview-02 | 100 | 2/28/2024 |
8.1.5-preview-01 | 93 | 2/19/2024 |
8.1.4 | 158 | 2/15/2024 |
8.1.3 | 116 | 2/13/2024 |
8.1.3-preview-07 | 89 | 2/13/2024 |
8.1.3-preview-06 | 99 | 2/12/2024 |
8.1.3-preview-05 | 106 | 2/9/2024 |
8.1.3-preview-04 | 93 | 2/8/2024 |
8.1.3-preview-03 | 81 | 2/7/2024 |
8.1.3-preview-02 | 80 | 2/2/2024 |
8.1.3-preview-01 | 85 | 2/2/2024 |
8.1.2 | 126 | 2/1/2024 |
8.1.2-preview-9 | 89 | 1/22/2024 |
8.1.2-preview-8 | 85 | 1/19/2024 |
8.1.2-preview-7 | 87 | 1/19/2024 |
8.1.2-preview-6 | 81 | 1/19/2024 |
8.1.2-preview-5 | 88 | 1/19/2024 |
8.1.2-preview-4 | 87 | 1/19/2024 |
8.1.2-preview-3 | 83 | 1/18/2024 |
8.1.2-preview-2 | 100 | 1/18/2024 |
8.1.2-preview-16 | 71 | 1/31/2024 |
8.1.2-preview-15 | 97 | 1/31/2024 |
8.1.2-preview-14 | 72 | 1/25/2024 |
8.1.2-preview-13 | 90 | 1/25/2024 |
8.1.2-preview-12 | 86 | 1/23/2024 |
8.1.2-preview-11 | 86 | 1/23/2024 |
8.1.2-preview-10 | 88 | 1/22/2024 |
8.1.2-preview-1 | 83 | 1/18/2024 |
8.1.1 | 125 | 1/18/2024 |
8.1.0 | 101 | 1/18/2024 |
8.0.3 | 144 | 12/29/2023 |
8.0.1 | 127 | 12/14/2023 |
8.0.0 | 134 | 12/7/2023 |
6.0.4.3 | 104 | 12/29/2023 |
6.0.4.2 | 123 | 12/20/2023 |
6.0.4.1 | 186 | 12/19/2023 |
6.0.4 | 130 | 12/4/2023 |
6.0.3.20 | 117 | 11/27/2023 |
6.0.3.19 | 125 | 11/22/2023 |