ZayniFramework.Middle.Service 2.2.1

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

// Install ZayniFramework.Middle.Service as a Cake Tool
#tool nuget:?package=ZayniFramework.Middle.Service&version=2.2.1

Middleware ServiceHost example.

The Middle.ServiceHost is a self-host application middleware service module. Any kind of .NET application can add package reference of the ZayniFramework.Middle.Service nupkg, then your application will be able to serve any clinet-side application by using this middleware serivce.

First, add a serviceHostConfig.json config file in your app project.<br/> You can use TCPSocket, WebSocket or RabbitMQ protocol. Each of them support RPC (Request & Response), Message Publish and Service Event Listening.

Something like this...

{
    "enableConsoleTracingLog": true,
    "serviceHosts": [
        {
            "serviceName": "PaymentService",
            "remoteHostType": "TCPSocket",
            "hostName": "GCP-Production",
            "enableActionLogToDB": true,
            "enableActionLogToFile": true
        },
        {
            "serviceName": "OrderService",
            "remoteHostType": "RabbitMQ",
            "hostName": "GCP-Production",
            "enableActionLogToDB": true,
            "enableActionLogToFile": true
        },
        {
            "serviceName": "WealthManagementService",
            "remoteHostType": "RabbitMQ",
            "hostName": "Azure-Production",
            "enableActionLogToDB": true,
            "enableActionLogToFile": true
        }
    ],
    "tcpSocketHostSettings": {
        "defaultHost": "GCP-Production",
        "hosts": [
            {
                "hostName": "GCP-Production",
                "tcpPort": 5590,
                "tcpBufferSizeKB": 10
            },
            {
                "hostName": "Azure-Production",
                "tcpPort": 5590,
                "tcpBufferSizeKB": 10
            }
        ]
    },
    "webSocketHostSettings": {
        "defaultHost": "GCP-Production",
        "hosts": [
            {
                "hostName": "GCP-Production",
                "hostBaseUrl": "ws://0.0.0.0:5580",
                "whitelist": []
            },
            {
                "hostName": "Azure-Production",
                "hostBaseUrl": "ws://0.0.0.0:5580",
                "whitelist": []
            }
        ]
    },
    "rabbitMQSettings": {
        "defaultHost": "Azure-Production",
        "hosts": [
            {
                "hostName": "GCP-Production",
                "mbHost": "XXX",
                "mbPort": 5672,
                "mbUserId": "XXX",
                "mbPassword": "XXX",
                "mbVHost": "SomeHost",
                "msgRoutingKey": "Event.Client.",
                "msgQueue": "Middle.Server.ListenClient.Msg",
                "rpcQueue": "Middle.Server.RPC",
                "rpcRoutingKey": "RPC.Server.",
                "publishDefaultExchange": "Middle.Test.Topic",
                "publishExchange": "Middle.Test.Topic",
                "publishRoutingKey": "Event.Server."
            },
            {
                "hostName": "Azure-Production",
                "mbHost": "XXX",
                "mbPort": 5672,
                "mbUserId": "XXX",
                "mbPassword": "XXX",
                "mbVHost": "SomeHost",
                "msgRoutingKey": "Event.Client.",
                "msgQueue": "Middle.Server.ListenClient.Msg",
                "rpcQueue": "Middle.Server.RPC",
                "rpcRoutingKey": "RPC.Server.",
                "publishDefaultExchange": "Middle.Test.Topic",
                "publishExchange": "Middle.Test.Topic",
                "publishRoutingKey": "Event.Server."
            }
        ]
    }
}

Then, write your DTO (Data Transfer Object) class for communication with outside applications.<br/> You can also use ZayniFramework.Validation's validation attribute on your DTO's properties.

using Newtonsoft.Json;
using System;
using ZayniFramework.Validation;


namespace ServiceHost.Test.Entity
{
    /// <summary>Some DTO class
    /// </summary>
    [Serializable()]
    public class SomethingDTO
    {
        /// <summary>Some message
        /// </summary>
        [NotNullOrEmpty( Message = "'someMsg' is invalid." )]
        [JsonProperty( PropertyName = "someMsg" )]
        public string SomeMessage { get; set; }

        /// <summary>Some DateTime
        /// </summary>
        [JsonProperty( PropertyName = "someDate" )]
        public DateTime SomeDate { get; set; }

        /// <summary>Some double number
        /// </summary>
        [JsonProperty( PropertyName = "magicNumber" )]
        public double SomeMagicNumber { get; set; }

        /// <summary>Some Int32 number
        /// </summary>
        [JsonProperty( PropertyName = "luckyNumber" )]
        public int LuckyNumber { get; set; }

        /// <summary>Some boolean value
        /// </summary>
        [JsonProperty( PropertyName = "isSuperXMan" )]
        public bool IsSuperMan { get; set; }
    }
}

Then, you can write your ServiceAction in your own class library project.<br/> Add namespace using.

using ZayniFramework.Common;
using ZayniFramework.Logging;
using ZayniFramework.Middle.Service;
using ZayniFramework.Serialization;

Write your ServieAction class and extends ServiceAction abstract class.

/// <summary>Some Servie Action
/// </summary>
public class MagicTestAction : ServiceAction<SomethingDTO, Result<MagicDTO>>

Write your constructor and pass the action name to the base class.

/// <summary>Constructor.
/// </summary>
public MagicTestAction() : base( "MagicTestAction" )
{
    // pass
}

Override the Execute method. You can implement your business logic here.<br/> See, your application don't know what kind of protocol or communication framework is using now. The only you need to focus is your business logic!

/// <summary>Execute Action. Your business logic here...
/// </summary>
public override void Execute()
{
    Response = new Result<MagicDTO>()
    {
        IsSuccess = false,
        Data      = null
    };

    Logger.WriteInformationLog( this, $"Receive SomethingDTO is {Environment.NewLine}{JsonConvertUtil.SerializeInCamelCase( Request )}", nameof ( Execute ) );

    SomethingDTO reqDTO = Request;

    var resDTO = new MagicDTO()
    {
        MagicWords = $"You should not wake me up... {Guid.NewGuid().ToString()}",
        MagicTime  = DateTime.Now
    };

    if ( 7.77 == reqDTO.SomeMagicNumber )
    {
        resDTO.TestDouble = 999.999;
    }

    Response.Data      = resDTO;
    Response.IsSuccess = true;
}

Then, you need to inject your ServiceAction to the ServiceActionContainer.

MiddlewareService.InitializeServiceActionHandler = () => 
{
    var magicTestAction = new MagicTestAction();
    ServiceActionContainerManager.Add( "PaymentService", magicTestAction.Name, magicTestAction.GetType() );
    ServiceActionContainerManager.Add( "OrderService", magicTestAction.Name, magicTestAction.GetType() );
    return new Result() { IsSuccess = true };
};

Finally, you just need to start the Middle.ServiceHost service in your application.

var configPath = "./Configs/serviceHostConfig.json";
var r = new MiddlewareService().StartService( "PaymentService", path: configPath );
var j = new MiddlewareService().StartService( "OrderService", path: configPath );

More sample, you can go to Test/WebAPI.Test directory to see the complete sample code.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on ZayniFramework.Middle.Service:

Package Downloads
ZayniFramework.Middle.Service.Client

The Middle.Service.Client is the client SDK for Middle.Service module. You can use it to connect, send RPC request or publish message to the server side's service host very easy. Support TCPSocket, WebSocket and RabbitMQ protocol. GitLab Repository: https://gitlab.com/ponylin1985/zayniframework

ZayniFramework.Middle.Service.Grpc

This is an extension module for Zayni Framework's Middle.Service module. This extension module provide the gRPC RemoteHost service implementation for Middle.Service module. GitLab Repository: https://gitlab.com/ponylin1985/zayniframework

ZayniFramework.Middle.Service.HttpCore

This is an extension module for Zayni Framework's Middle.Service module. This extension module provide the HttpCoreRemoteHost implementation for Middle.Service module. This package support the .NET 6.0 or .NET Core target framework only. It doesn't support the .NET Framework projects. GitLab Repository: https://gitlab.com/ponylin1985/zayniframework

ZayniFramework.Caching.RemoteCache

This is a ZayniFramework build-in Remote Share Data Service. You can use the ZayniFramework.Caching module to store data into this service. Also it support telnent service commands. GitLab Repository: https://gitlab.com/ponylin1985/ZayniFramework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.142 136 3/19/2024
8.0.141 182 1/4/2024
8.0.140 229 12/17/2023
6.0.138 207 3/19/2024
6.0.137 451 9/20/2023
6.0.136 429 9/14/2023
6.0.135 458 9/10/2023
6.0.134 544 7/12/2023
6.0.133 528 7/10/2023
6.0.132 551 7/7/2023
6.0.131 621 6/19/2023
6.0.130 582 6/19/2023
6.0.129 11,235 7/2/2022
6.0.128 1,695 1/16/2022
6.0.127 1,624 1/15/2022
6.0.126 1,711 1/15/2022
6.0.125 1,025 1/8/2022
6.0.125-hotfix1 534 1/8/2022
6.0.124 1,058 1/7/2022
6.0.123 1,275 11/14/2021
5.0.129 2,313 7/2/2022
5.0.128 2,422 1/16/2022
5.0.125 1,319 1/8/2022
5.0.124 1,302 1/7/2022
5.0.123 1,636 11/14/2021
5.0.122 1,786 10/11/2021
5.0.121 1,826 5/1/2021
3.1.137 818 9/20/2023
3.1.136 799 9/14/2023
3.1.135 787 9/10/2023
3.1.134 949 7/12/2023
3.1.133 985 7/11/2023
3.1.132 950 7/8/2023
3.1.131 1,089 6/19/2023
3.1.130 1,813 2/1/2023
3.1.129 3,395 7/2/2022
3.1.128 3,598 1/16/2022
3.1.125 1,854 1/8/2022
3.1.124 1,764 1/7/2022
3.1.123 2,312 11/14/2021
3.1.122 2,667 10/11/2021
3.1.121 2,734 5/1/2021
2.31.120 1,832 3/14/2021
2.30.115 5,422 3/6/2021
2.30.114 1,746 3/6/2021
2.20.101 2,434 3/1/2021
2.19.3 1,828 2/11/2021
2.19.2 14,127 2/6/2021
2.19.1 2,072 1/6/2021
2.19.0 2,102 1/1/2021
2.18.3 3,298 12/27/2020
2.18.2 4,262 8/29/2020
2.18.1 7,459 8/26/2020
2.18.0 7,672 8/20/2020
2.17.135 3,451 8/19/2020
2.17.134 3,551 7/28/2020
2.17.133 3,508 7/27/2020
2.17.132 3,489 7/18/2020
2.17.131 3,700 7/11/2020
2.16.130 3,334 6/13/2020
2.15.128 3,550 6/3/2020
2.15.127 3,458 5/31/2020
2.15.126 4,421 4/30/2020
2.14.122 3,237 4/13/2020
2.13.100 3,406 3/12/2020
2.12.51 3,421 2/18/2020
2.11.50 7,507 2/10/2020
2.10.44 8,931 1/30/2020
2.9.43 8,927 1/11/2020
2.8.42 8,947 1/10/2020
2.8.41 8,909 1/5/2020
2.7.40 8,713 1/2/2020
2.7.39 8,621 1/2/2020
2.7.38 9,005 1/1/2020
2.6.37 8,843 12/23/2019
2.6.35 9,090 12/4/2019
2.6.1 8,894 12/2/2019
2.6.0 8,726 11/28/2019
2.5.2 9,243 11/26/2019
2.5.1 8,845 11/12/2019
2.5.0 8,603 11/9/2019
2.4.3 9,140 10/16/2019
2.4.2 8,628 10/16/2019
2.4.1 8,846 9/20/2019
2.3.113 1,779 3/6/2021
2.3.112 1,709 3/6/2021
2.3.28 8,694 9/19/2019
2.3.27 8,821 8/30/2019
2.3.26 8,819 8/20/2019
2.3.25 8,671 8/12/2019
2.3.22 8,762 7/31/2019
2.3.21 8,670 7/20/2019
2.3.20 8,294 6/22/2019
2.3.19 8,759 6/14/2019
2.3.18 8,782 6/13/2019
2.3.17 8,847 6/13/2019
2.3.15 8,406 6/8/2019
2.3.14 8,615 6/8/2019
2.3.13 8,658 5/30/2019
2.3.12 4,191 5/24/2019
2.3.11 4,100 5/24/2019
2.3.10 4,124 5/21/2019
2.3.9 3,933 5/9/2019
2.3.8 4,331 5/8/2019
2.3.7 4,190 4/30/2019
2.3.6 4,270 4/23/2019
2.3.5 4,222 4/19/2019
2.3.4 4,142 4/18/2019
2.3.3 4,113 4/17/2019
2.3.2 4,317 4/6/2019
2.3.1 4,264 12/15/2018
2.3.0 4,279 12/7/2018
2.2.7 3,409 11/30/2018
2.2.6 4,471 11/25/2018
2.2.5 3,676 11/23/2018
2.2.4 3,527 11/22/2018
2.2.3 2,731 11/21/2018
2.2.2 2,571 11/19/2018
2.2.1 2,181 11/17/2018
2.2.0 1,840 11/16/2018
2.1.0 1,725 11/15/2018
2.0.1 1,043 11/6/2018
2.0.0 1,166 11/4/2018