PaulPhillips.Framework.Feature
1.0.13-alpha
See the version list below for details.
dotnet add package PaulPhillips.Framework.Feature --version 1.0.13-alpha
NuGet\Install-Package PaulPhillips.Framework.Feature -Version 1.0.13-alpha
<PackageReference Include="PaulPhillips.Framework.Feature" Version="1.0.13-alpha" />
paket add PaulPhillips.Framework.Feature --version 1.0.13-alpha
#r "nuget: PaulPhillips.Framework.Feature, 1.0.13-alpha"
// Install PaulPhillips.Framework.Feature as a Cake Addin #addin nuget:?package=PaulPhillips.Framework.Feature&version=1.0.13-alpha&prerelease // Install PaulPhillips.Framework.Feature as a Cake Tool #tool nuget:?package=PaulPhillips.Framework.Feature&version=1.0.13-alpha&prerelease
PaulPhillips.Framework.Feature (Microservice Framework)
A small framework that combines a set of common features that a typical Microservice would access which supports Vertical Slice Architecture.
Build in support for:
- Framework to supports Vertical Slice Architecture
- Idempotency
- Event Management (Rabbit MQ)
- Structured Logging (Jeager), Error Handling and Security
- Security (JWT)
Terminology
- Feature: This embodies the vertical slice of the framework, encapsulating individual core logic.
- Command: Signifies an action to be executed on the server, in line with the CQRS pattern.
- Query: Denotes read-only actions, also integral to the CQRS pattern.
A feature and only be a Command OR a Query, not both.
Requirements
- NET 8
- Redis
- Jeager
- Rabbit MQ
Though the above are requirements, you can swap Redis, Jeager and RabbitMQ to alternative platforms if required.
Getting Started
Create a .NET Minimal API (.NET) project and install (controllers are not required by the framework)
dotnet add package PaulPhillips.Framework.Feature --version 1.0.12-alpha
Package: NuGet\Install-Package PaulPhillips.Framework.Feature -Version 1.0.12-alpha
To start with, your program.cs should something like below:
using PaulPhillips.Framework.Feature.Core;
using PaulPhillips.Framework.Feature.Helpers;
using PaulPhillips.Framework.Feature.Middlewares;
var builder = WebApplication.CreateBuilder(args);
builder.Services.RegisterFeatureAll();
var app = builder.Build();
app.UseMiddleware<FeatureHealthMiddleware>();
#if !DEBUG
app.UseMiddleware<FeatureSecurityMiddleware>(); Include this middleware if you want to test with JWT
#endif
app.UseMiddleware<FeaterCoreMiddleware>();
app.Run();
Next, we need to add some configuration to AppSettings.json, this will configure endpoints for Redis etc.
"Health": {
"Alive": "Health/Alive",
"Ready": "Health/Ready"
},
"Security": {
"Issuer": "http://localhost:8480/realms/Paul",
"Audience": "account",
"Key": "ZUhBMVhVakppWkJMNXkxWVVjWVNYNllTTC15YkxIRTlQemJ3ZkpFVE00Zw==",
"RequireHttpsMetadata": false,
"Enabled": true
},
"Idempotency": {
"Host": "localhost"
},
"Events": {
"Host": "127.0.0.1",
"UserName": "guest",
"Password": "guest"
}
Security: Standard JWT configuration
Idempotency: Redis instance
Events: Rabbit MQ Instance
Creating a Command Feature
A feature group collates all code, assets etc into a single folder (the feature).
There are no rules how are you create your folder structure, this is up to you, but in the example I will be creating a folder called FeatureDemo. This example, I will be simply return back
Please follow the following steps:
- Create a folder called "Features"
- Under the folder "Features", Create Folder caller "FeatureDemo"
- Under the "Feature" create a folder called "Models"
- Under Models, create a class called RequestModel with a public string property called "FullName".
- Under Models create another called ResponseModel with a public string property called "FirstName"
- Under the Feature folder, create a class called CreateCustomerFeature that inherits from Command<RequestModel,ResponseModel>
- Last step, you will need to override a single method ProcessAsync (this is where your core logic will reside)
Your Command Feature should look something like:
using OpenTracing;
using PaulPhillips.Feature.BasicExample.Features.FeatureDemo.Models;
using PaulPhillips.Framework.Feature.Commands;
namespace PaulPhillips.Feature.BasicExample.Features.FeatureDemo
{
public class CreateCustomerFeature : Command<RequestModel,ResponseModel>
{
public override async Task<dynamic> ProcessAsync(ISpan tracingSpan)
{
if (!string.IsNullOrWhiteSpace(Request?.FullName))
{
var nameToSplit = Request.FullName.Split(" ");
var responseModel = new ResponseModel { FirstName = nameToSplit[0] };
return await Task.FromResult(responseModel);
}
return await Task.FromResult(new ResponseModel());
}
}
}
The above is just an example at this stage and will not cover every aspect of the framework at this stage.
Now we need to register the feature with the core framework, this can be done in the program class.
var app = builder.Build();
FeatureFactory.Features.Add("CreateCustomer", typeof(CreateCustomerFeature));
That is it, a new feature has been created.
Use postman or any other client to perform a post.
@PaulPhillips.Feature.BasicExample_HostAddress = http://localhost:5062
POST {{PaulPhillips.Feature.BasicExample_HostAddress}}/CreateCustomer
Accept: application/json
{
"FullName": "Paul Phillips"
}
###
Result:
{
"ValidationResult": null,
"Response": {
"FirstName": "Paul"
}
}
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
- Autofac (>= 8.0.0)
- AutoMapper (>= 12.0.1)
- FakeItEasy (>= 8.1.0)
- FluentValidation (>= 11.9.0)
- Jaeger (>= 1.0.3)
- Memphis.Client (>= 0.7.3)
- Microsoft.AspNetCore (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.2)
- NRedisStack (>= 0.11.0)
- OpenTracing.Contrib.NetCore (>= 0.9.0)
- RabbitMQ.Client (>= 6.8.1)
- System.IdentityModel.Tokens.Jwt (>= 7.2.0)
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.16-alpha | 65 | 3/30/2024 |
1.0.14-alpha | 63 | 3/3/2024 |
1.0.13-alpha | 64 | 2/28/2024 |
1.0.12-alpha | 65 | 2/25/2024 |