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 196 3/19/2024
8.0.141 231 1/4/2024
8.0.140 278 12/17/2023
6.0.138 278 3/19/2024
6.0.137 509 9/20/2023
6.0.136 494 9/14/2023
6.0.135 526 9/10/2023
6.0.134 613 7/12/2023
6.0.133 592 7/10/2023
6.0.132 610 7/7/2023
6.0.131 685 6/19/2023
6.0.130 654 6/19/2023
6.0.129 11,754 7/2/2022
6.0.128 1,774 1/16/2022
6.0.127 1,686 1/15/2022
6.0.126 1,776 1/15/2022
6.0.125 1,077 1/8/2022
6.0.125-hotfix1 594 1/8/2022
6.0.124 1,123 1/7/2022
6.0.123 1,338 11/14/2021
5.0.129 2,382 7/2/2022
5.0.128 2,501 1/16/2022
5.0.125 1,384 1/8/2022
5.0.124 1,371 1/7/2022
5.0.123 1,702 11/14/2021
5.0.122 1,866 10/11/2021
5.0.121 1,900 5/1/2021
3.1.137 918 9/20/2023
3.1.136 888 9/14/2023
3.1.135 889 9/10/2023
3.1.134 1,030 7/12/2023
3.1.133 1,080 7/11/2023
3.1.132 1,046 7/8/2023
3.1.131 1,152 6/19/2023
3.1.130 1,913 2/1/2023
3.1.129 3,498 7/2/2022
3.1.128 3,700 1/16/2022
3.1.125 1,935 1/8/2022
3.1.124 1,869 1/7/2022
3.1.123 2,411 11/14/2021
3.1.122 2,732 10/11/2021
3.1.121 2,823 5/1/2021
2.31.120 1,888 3/14/2021
2.30.115 5,524 3/6/2021
2.30.114 1,814 3/6/2021
2.20.101 2,516 3/1/2021
2.19.3 1,892 2/11/2021
2.19.2 14,189 2/6/2021
2.19.1 2,145 1/6/2021
2.19.0 2,154 1/1/2021
2.18.3 3,444 12/27/2020
2.18.2 4,336 8/29/2020
2.18.1 7,550 8/26/2020
2.18.0 7,773 8/20/2020
2.17.135 3,548 8/19/2020
2.17.134 3,633 7/28/2020
2.17.133 3,632 7/27/2020
2.17.132 3,573 7/18/2020
2.17.131 3,748 7/11/2020
2.16.130 3,434 6/13/2020
2.15.128 3,647 6/3/2020
2.15.127 3,574 5/31/2020
2.15.126 4,505 4/30/2020
2.14.122 3,331 4/13/2020
2.13.100 3,499 3/12/2020
2.12.51 3,472 2/18/2020
2.11.50 7,583 2/10/2020
2.10.44 9,020 1/30/2020
2.9.43 8,982 1/11/2020
2.8.42 9,024 1/10/2020
2.8.41 9,001 1/5/2020
2.7.40 8,839 1/2/2020
2.7.39 8,713 1/2/2020
2.7.38 9,075 1/1/2020
2.6.37 8,922 12/23/2019
2.6.35 9,169 12/4/2019
2.6.1 8,970 12/2/2019
2.6.0 8,822 11/28/2019
2.5.2 9,315 11/26/2019
2.5.1 8,938 11/12/2019
2.5.0 8,728 11/9/2019
2.4.3 9,253 10/16/2019
2.4.2 8,729 10/16/2019
2.4.1 8,933 9/20/2019
2.3.113 1,841 3/6/2021
2.3.112 1,785 3/6/2021
2.3.28 8,772 9/19/2019
2.3.27 8,881 8/30/2019
2.3.26 8,897 8/20/2019
2.3.25 8,774 8/12/2019
2.3.22 8,912 7/31/2019
2.3.21 8,783 7/20/2019
2.3.20 8,394 6/22/2019
2.3.19 8,891 6/14/2019
2.3.18 8,905 6/13/2019
2.3.17 8,969 6/13/2019
2.3.15 8,508 6/8/2019
2.3.14 8,672 6/8/2019
2.3.13 8,743 5/30/2019
2.3.12 4,301 5/24/2019
2.3.11 4,202 5/24/2019
2.3.10 4,202 5/21/2019
2.3.9 4,056 5/9/2019
2.3.8 4,431 5/8/2019
2.3.7 4,275 4/30/2019
2.3.6 4,377 4/23/2019
2.3.5 4,326 4/19/2019
2.3.4 4,226 4/18/2019
2.3.3 4,219 4/17/2019
2.3.2 4,444 4/6/2019
2.3.1 4,374 12/15/2018
2.3.0 4,369 12/7/2018
2.2.7 3,504 11/30/2018
2.2.6 4,592 11/25/2018
2.2.5 3,776 11/23/2018
2.2.4 3,599 11/22/2018
2.2.3 2,806 11/21/2018
2.2.2 2,635 11/19/2018
2.2.1 2,237 11/17/2018
2.2.0 1,893 11/16/2018
2.1.0 1,781 11/15/2018
2.0.1 1,089 11/6/2018
2.0.0 1,197 11/4/2018