1k0n.Pipeline.Messaging.CodeGenerator
1.0.2
See the version list below for details.
dotnet add package 1k0n.Pipeline.Messaging.CodeGenerator --version 1.0.2
NuGet\Install-Package 1k0n.Pipeline.Messaging.CodeGenerator -Version 1.0.2
<PackageReference Include="1k0n.Pipeline.Messaging.CodeGenerator" Version="1.0.2" />
paket add 1k0n.Pipeline.Messaging.CodeGenerator --version 1.0.2
#r "nuget: 1k0n.Pipeline.Messaging.CodeGenerator, 1.0.2"
// Install 1k0n.Pipeline.Messaging.CodeGenerator as a Cake Addin #addin nuget:?package=1k0n.Pipeline.Messaging.CodeGenerator&version=1.0.2 // Install 1k0n.Pipeline.Messaging.CodeGenerator as a Cake Tool #tool nuget:?package=1k0n.Pipeline.Messaging.CodeGenerator&version=1.0.2
1k0n Request/Response Pattern Code Generator
Creating a Messaging Client using 1k0n.Pipeline.StronglyTypedPipeline
This code generator creates the code to implement a Request/Response access pattern for a strongly-typed pipeline.
using _1k0n.Pipeline.StronglyTypedPipeline;
using _1k0n.Pipeline.StronglyTypedPipeline.Messaging;
Creating a Contract
Create an interface to be used as the strongly-typed messaging contract.
The name of Request methods must end with "Request"
The name of Response methods must end with "Response"
All methods must return a Task object
The parameters of all methods must start with a string parameter called "Id" and a HeadersCollection? called "headers"
Response methods must only have 3 parameters (Id, headers, and the response data)
[GenerateMessages]
public interface IRequestResponseMessageHandler
{
[FailedResponse]
Task ErrorResponse(string Id, HeadersCollection? headers, string error);
Task GetTokenRequest(string Id, HeadersCollection? headers, string username, string password);
Task GetTokenResponse(string Id, HeadersCollection? headers, string token);
Task GetMessagesRequest(string Id, HeadersCollection? headers);
Task GetMessagesResponse(string Id, HeadersCollection? headers, List<string?>? messages);
}
Decorate the interface with a GenerateMessagesAttribute so that the Pipeline will auto generate the messages needed for the contract.
To implement an Error response, decorate it with a FailedResponseAttribute
Note: Every Request needs a matching Response.
Responses can be declared without a Request if there are different return types or multi-path responses are needed. You can use the normal Request call, the server can repond with any Response, the message will be recieved to the correct Request call by it's Id.
Create the MessageService partial class
[MessageService(typeof(IRequestResponseMessageHandler))]
public partial class GeneratedMessageService
{
}
Decorate the class with a MessageServiceAttribute so that the code generator will generate the code for this message service.
In the attribute constructor, pass the Type of the message contract interface.
Create the MessageHandler partial class
public partial class RequestResponseMessageHandler
{
}
This class must be named the same as the interface minus the 'I' at the begining.
Generate the code
Once the Interface and two partial classes are created, Rebuild the solution. The code generator will build the MessageService and MessageHandler classes.
Using the generated classes with 1k0n.Pipline.StronglyTypedPipeline
Using the generated classes is easy using Dependency Injection.
services.AddScoped<MessageCache>();
services.AddMessagePipeline<IRequestResponseMessageHandler, RequestResponseMessageHandler>();
services.AddScoped<IMessageService, GeneratedMessageService>();
copyright © 2022 John Meyer Jr. - For use with the 1k0n.Pipeline library -
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Corrected namespace error