Apps.Contextsphere 8.0.1

dotnet add package Apps.Contextsphere --version 8.0.1                
NuGet\Install-Package Apps.Contextsphere -Version 8.0.1                
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="Apps.Contextsphere" Version="8.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Apps.Contextsphere --version 8.0.1                
#r "nuget: Apps.Contextsphere, 8.0.1"                
#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 Apps.Contextsphere as a Cake Addin
#addin nuget:?package=Apps.Contextsphere&version=8.0.1

// Install Apps.Contextsphere as a Cake Tool
#tool nuget:?package=Apps.Contextsphere&version=8.0.1                

Overview

Contextsphere provides a lightweight substitute for message bus/hub functionality that is intended for front-end development use.

IMPORTANT: Versions 8.0.1 or higher are not compatible with previous ones.

Usage

Register a singleton IContext in the app's DI container.

    ...

    builder.Services.AddSingleton<IContext, Context>();

    ...

The same IContext instance can then be injected anywhere needed:

    public class MyNode1 : IHandle<MyItem1, MyResult1, MyParameter1>, ...
    {
        ...

        public MyNode1(IContext context, ...)
        {
            // include this node in the message loop
            context.Include(this);
            ...
        }

        ...

        public MyResult1? Handle(MyItem1 item, MyParameter1 param)
        {
            ...

            // dispatch an item like so;
            context.Dispatch<MyItemX>(itemX); 

            // or;
            var resultY = context.Dispatch<MyItemY, MyResultY>(itemY); 

            // or;
            var resultZ = context.Dispatch<MyItemZ, MyResultZ, MyParamZ>(itemZ, paramZ); 

            ...
        }
    }

Apply [ContextNode] attribute to a class for another way to include it in the messaging context.

    [ContextNode]
    public class MyNode2 : IHandleAsync<MyItem2, MyResult2, MyParameter2>, ...
    {
        // inject IF NEEDED
        // private readonly IServiceProvider serviceProvider;


        public async Task<Result<MyResult2>> HandleAsync(MyItem2 item, MyParameter2 param, CancellationToken token)
        {
            ...

            // IF NEEDED, get the IContext instance in the IServiceProvider,
            var context = serviceProvider.GetService<IContext>() ?? throw new NullReferenceException();

            // so you can dispatch an item and await for result like so;
            var resultX = await context.DispatchAsync<MyItemX, MyResultX>(itemX, token).ConfigureAwait(false);

            // or;
            var resultY = await context.DispatchAsync<MyItemY, MyResultY, MyParamY>(itemY, paramY, token).ConfigureAwait(false);

            ...
        }
    }

Concerns/Feedbacks?

You may reach me thru jakes_parane@hotmail.ph. Happy coding!

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • 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
8.0.1 256 12/6/2023
7.1.6 165 11/12/2023
7.1.5 127 11/12/2023
7.1.4 136 11/12/2023
7.1.3 125 11/12/2023
7.1.2 117 11/12/2023
7.1.1 118 11/12/2023
7.1.0 139 11/11/2023
7.0.9 132 11/11/2023
7.0.8 122 11/11/2023
7.0.7 169 10/25/2023
7.0.6 161 10/25/2023
7.0.5 150 10/24/2023
7.0.4 147 10/17/2023
7.0.3 160 10/15/2023
1.3.4 439 8/26/2022 1.3.4 is deprecated because it is no longer maintained.