Qoollo.MassTransitIdentity 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Qoollo.MassTransitIdentity --version 1.0.2                
NuGet\Install-Package Qoollo.MassTransitIdentity -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="Qoollo.MassTransitIdentity" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Qoollo.MassTransitIdentity --version 1.0.2                
#r "nuget: Qoollo.MassTransitIdentity, 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 Qoollo.MassTransitIdentity as a Cake Addin
#addin nuget:?package=Qoollo.MassTransitIdentity&version=1.0.2

// Install Qoollo.MassTransitIdentity as a Cake Tool
#tool nuget:?package=Qoollo.MassTransitIdentity&version=1.0.2                

MassTransit Identity

Library for actor identification through services in MassTransit. Repository also contains simple example projects with providers and consumers.

Usage steps:

1. Add nessesary services to service collection in your project

1.1 Add Identity Token to service collection

Put this code in your ConfigureServices method:

services.AddScoped<MassTransitIdentityToken>();

1.2 Add filter configurations to your MassTransit transport configuration

Add these lines:

cfg.UsePublishFilter(typeof(IdentityTokenPublishFilter<>), context);
cfg.UseSendFilter(typeof(IdentityTokenSendFilter<>), context);
cfg.UseConsumeFilter(typeof(IdentityTokenConsumeFilter<>), context);

WARNING: It is strongly recommended to add all filters to configuration, no matter for what purposes you are going to use Identity Token: receiving, sending/publishing or redirecting.

2. Use token where you need to

2.1 Put token as dependency in service constructor

public class ScopedService
{
    private readonly MassTransitIdentityToken _token;
    private readonly ILogger<ScopedService> _logger;
    private readonly IRequestClient<SomeMassTransitRequest> _requestClient;

    public ScopedService(MassTransitIdentityToken token, 
            ILogger<ScopedService> logger,
            IRequestClient<MassTransitContract> requestClient)
    {
        _token = token;
        _logger = logger;
        _requestClient = requestClient;
    }
}

2.2 Create identity token for your scope

Put token into Value property of MassTransitIdentityToken instance. After this you can call services, which use identity token. What is more important, now you can send and publish messages to other MassTransit actors like consumers.

public class ScopedService
{
    ...

    public void Foo(Guid clientId)
    {
        _token.Value = clientId;

        var response = _requestClient.GetResponse<SomeMassTansitResponse>(new { });
    }
}

TIP: As you can see, identity token value type is Guid.

2.3 Get identity token in other services

public class AnotherServiceConsumer : IConsumer<SomeMassTransitRequest>
{
    private readonly MassTransitIdentityToken _token;
    private readonly ILogger<AnotherServiceConsumer> _logger;

    public SomeConsumer(MassTransitIdentityToken token, 
        ILogger<AnotherServiceConsumer> logger)
    {
        _token = token;
        _logger = logger;
    }

    public async Task Consume(ConsumeContext<SomeMassTransitRequest> context)
    {
        _logger.LogInformation($"{typeof(AnotherServiceConsumer)}: Consumed token {_token.Value}");

        await context.RespondAsync<SomeMassTansitResponse>(new { });
    }
}

TIP: Identity token secured from rewriting.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in 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.0.3 1,188 7/15/2022
1.0.2 1,198 7/11/2022
1.0.1 1,013 4/6/2022
1.0.0 278 3/14/2022

Library for actor identification through services in MassTransit.