Pomegranate 1.0.1

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

// Install Pomegranate as a Cake Tool
#tool nuget:?package=Pomegranate&version=1.0.1                

Welcome to Pomegranate

Pomegranate is an extreemly flexible Pub/Sub framework designed for any type of transport, or even no transport at all. You can use Pomegranate locally, or write a transport that uses Unix/Windows sockets for IPC, or use WebSockets for going across the WAN. The method of transport it entirely up to you.

Pomegranate also allows you to bring your own serialization. By default Pomegranate provides a serializer that uses DataContractSerializer and doesn't require any kind of attributes for serialization, you can simply send any object that implements IPomegranateContract over Pomegranate, so long as the receiving end shares the same object definition (likely in some kind of shared libary).

Quick Start

Here are some really basic examples that show how use Pomegranate.

Let's create a new contract type that is shared between all projects use Pomegranate for communication, we could put this in a shared libary

public class MessageContract : IPomegranateContract
{
    public string? Message { get; init; }//a simple message

    public MessageContract() { }//default .ctor required
    public MessageContract(string message) { Message = message; }
}

Now let's subscribe to a particular ContractType and Namespace

public class ExampleNode
{
    private readonly INode m_node;

    public ExampleNode(INode node)
    {
        m_node = node;
        
        //Here we subscribe to all MessageContracts within the /msg namespace.
        //Strings are used to define namespaces, but they are converted into hashes
        //to avoid any type of string comparisons and string manipulations
        var handle = m_node.Subscribe<MessageContract>(ReceiveMessage, @"/msg", typeInheritance: false, namespaceInheritance: false);//Subscribe<T> returns an IDisposable handle that is used to end the subscription when you no longer need it
        
        //and while you have to use a string to define the Namespace, it is probably best to come of with a way to use
        //deterministic strings, entirely removing the need for "magic strings". A simple example here might be to replace
        //@"/msg" with nameof(MessageContract).
        
        //as optional parameters you can specify whether or not want to listen for sub-types, 
        //as well as whether or not we want to listen to parent namespaces. The default is false
        //for both options.
    }

    //Whenever a contract of MessageContract type is received on the @"/msg", this method will be called.
    //Feel free to make subsciptions asynchronous if needed. 
    private void ReceiveMessage(Guid sender, MessageContract contract)
    {
        Console.WriteLine(contract.Message);
    }
}

You can also use the Observable/Observer pattern which makes it easy to use with ReactiveUI:

IObservable<MessageContract> observable = m_node.GetObservable<MessageContract>(@"/msg", typeInheritance: false, namespaceInheritance: false, autoDispose: false);

//GetObservable returns a PomegranateObservable<T> type which implements IObservable<T> as well as IDisposable which is not normal for Observables.
//It implements IDisposable because it wraps a Pomegranate subscription which uses an IDisposable handle to know when to close the subscription.
//There is an optional autoDispose parameter that defaults to false. If set to true the PomegranateObservable will call dispose when the last subscriber as been removed.

There is a "Samples" directory in the repository that contains a working sample of using Pomegranate over WebSockets for a more in-depth example.

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.
  • net6.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
1.0.1 496 1/18/2022
1.0.0 437 1/18/2022