ApFrameworkLite 1.0.0
dotnet add package ApFrameworkLite --version 1.0.0
NuGet\Install-Package ApFrameworkLite -Version 1.0.0
<PackageReference Include="ApFrameworkLite" Version="1.0.0" />
paket add ApFrameworkLite --version 1.0.0
#r "nuget: ApFrameworkLite, 1.0.0"
// Install ApFrameworkLite as a Cake Addin #addin nuget:?package=ApFrameworkLite&version=1.0.0 // Install ApFrameworkLite as a Cake Tool #tool nuget:?package=ApFrameworkLite&version=1.0.0
ApFrameworkLite abstracts out cross cutting concerns like authorization, validation, logging, performance monitoring etc. hence keeps code clean without polluting other layers of code.
It also allows for a consistent approach across multiple components on different frameworks like Webapi, Window service, WPF, Console App etc. As each of these offer distinct ways to handle concerns like authorization and error handling.
This is lighter version of ApFramework (stripped to bare-bones)
HowToUse
Step 1: Get Request Processor
A few ways to do this
-Extend RequestProcessor class and add required pre and post methods. Then inject instance to constructor
-Create RequestProcessorFactory to return RequestProcessor instance with specific pre/post methods added
Step 2:
Call ProcessRequestAsync method on processor and pass in actual action to perform
Example -
Lets say, we have a function to 1. Get trades from data source (service, DB, etc. ) 2. Map to entity and return back object
public async Task<string> GetTrades(Datetime tradeDate)
{
var trades = await DataStore.GetTradesByDate(tradeDate);
var tradeJson = await Mapper.Map(trades);
return tradeJson;
}
This is missing calls to authorization, error handling, performance logging, event tracing etc. So rather than adding all this to function we can have a instance of RequestProcessor that is setup to all of these extra bits.
- Get RequestProcessor
IRequestProcessor requestProcessor = RequestProcessorFactory.GetRequestProcessor("With_Authorisation_ExceptionLogging_PerfromanceMonitoring");
- Abstract and wrap in delegate
RequestActionDelegate getTrades = async (bag) => {
var dataBag = bag as DataBag;
var trades = await DataStore.GetTradesByDate(tradeDate);
var tradeJson = await Mapper.Map(trades);
dataBag.MappedJson = tradeJson;
// Note: Databag is used for demonstration. It is useful when we want subsequence actions to have access to this information. We don't have to use it.
}
- Pass delegate to RequestProcessor for execution.
await requestProcessor.ProcessRequestAsync(getData, false);
- Get data from bag and return.
Refer to Tests.cs on Project website (Github)
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.1 is compatible. |
-
.NETCoreApp 3.1
- No dependencies.
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.0 | 367 | 12/12/2021 |