1k0n.Pipeline.Messaging.CodeGenerator 1.0.2

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="1k0n.Pipeline.Messaging.CodeGenerator" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add 1k0n.Pipeline.Messaging.CodeGenerator --version 1.0.2                
#r "nuget: 1k0n.Pipeline.Messaging.CodeGenerator, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 -

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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.1.0 447 11/13/2022
1.0.2 471 5/15/2022
1.0.1 470 5/10/2022

Corrected namespace error