ZayniFramework.Middle.Service 2.3.2

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

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

Middleware Middle.Service module 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.<br/>

If your application use the Middle.Service.Grpc module you can also config the gRPC protocol too. If your application use the Middle.Service.HttpCore module you can also config the HttpCore protocol too.

Something like this...<br/>

{
    "enableConsoleTracingLog": true,
    "serviceHosts": [
        {
            "serviceName": "PaymentService",
            "remoteHostType": "TCPSocket",
            "hostName": "GCP-Production",
            "enableActionLogToDB": true,
            "enableActionLogToFile": true,
            "autoStart": true                   // Default Value is true in internal framework
        }
    ],
    "tcpSocketHostSettings": {
        "defaultHost": "GCP-Production",
        "hosts": [
            {
                "hostName": "GCP-Production",
                "tcpPort": 5590,
                "tcpBufferSizeKB": 10
            }
        ]
    },
    "webSocketHostSettings": {
        "defaultHost": "GCP-Production",
        "hosts": [
            {
                "hostName": "GCP-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."
            }
        ]
    },
    "gRPCHostSettings": {
        "defaultHost": "GCP-Production",
        "hosts": [
            {
                "hostName": "GCP-Production",
                "gRPCHostServer": "0.0.0.0",
                "port": 1111
            }
        ]
    },
    "httpCoreSettings": {
        "hosts": [
            {
                "hostName": "GCP-Production",
                "hostBaseUrl": "http://0.0.0.0:5110"
            }
        ]
    }
}

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; }
    }
}

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" )
{
}

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 = Result.Create<MagicDTO()>();
    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.Success = true;
}

If you have your own customized implementaion of IRemoteHost as an extension protocol module. You can register you own implemented RemoteHost into the Middle.Service's internal container. Like this,

// Register a 'gRPCRemoteHost' IRemoteHost type into Middle.Service. The name is 'gRPC'.
// You have to register your own IRemoteHost type before MiddlewareService.StartService().
MiddlewareService.RegisterRemoteHostType<gRPCRemoteHost>( "gRPC" );

You can also register your ServiceAction without the serviceName, the Zayni Framework will register the ServiceActions for all the service host which the 'autoStart' setting value is true in serviceHostConfig.json file. Like this:

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

var configPath = "./Configs/serviceHostConfig.json";

// Start all the autoStarted service hosts.
var g = new MiddlewareService().StartServiceHosts( 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 123 3/19/2024
8.0.141 176 1/4/2024
8.0.140 225 12/17/2023
6.0.138 197 3/19/2024
6.0.137 438 9/20/2023
6.0.136 419 9/14/2023
6.0.135 452 9/10/2023
6.0.134 539 7/12/2023
6.0.133 525 7/10/2023
6.0.132 546 7/7/2023
6.0.131 616 6/19/2023
6.0.130 577 6/19/2023
6.0.129 11,118 7/2/2022
6.0.128 1,691 1/16/2022
6.0.127 1,620 1/15/2022
6.0.126 1,707 1/15/2022
6.0.125 1,022 1/8/2022
6.0.125-hotfix1 530 1/8/2022
6.0.124 1,054 1/7/2022
6.0.123 1,271 11/14/2021
5.0.129 2,308 7/2/2022
5.0.128 2,420 1/16/2022
5.0.125 1,314 1/8/2022
5.0.124 1,297 1/7/2022
5.0.123 1,634 11/14/2021
5.0.122 1,781 10/11/2021
5.0.121 1,821 5/1/2021
3.1.137 807 9/20/2023
3.1.136 785 9/14/2023
3.1.135 777 9/10/2023
3.1.134 933 7/12/2023
3.1.133 976 7/11/2023
3.1.132 941 7/8/2023
3.1.131 1,080 6/19/2023
3.1.130 1,804 2/1/2023
3.1.129 3,381 7/2/2022
3.1.128 3,590 1/16/2022
3.1.125 1,839 1/8/2022
3.1.124 1,756 1/7/2022
3.1.123 2,304 11/14/2021
3.1.122 2,659 10/11/2021
3.1.121 2,726 5/1/2021
2.31.120 1,827 3/14/2021
2.30.115 5,394 3/6/2021
2.30.114 1,746 3/6/2021
2.20.101 2,429 3/1/2021
2.19.3 1,823 2/11/2021
2.19.2 14,122 2/6/2021
2.19.1 2,067 1/6/2021
2.19.0 2,097 1/1/2021
2.18.3 3,276 12/27/2020
2.18.2 4,254 8/29/2020
2.18.1 7,451 8/26/2020
2.18.0 7,637 8/20/2020
2.17.135 3,443 8/19/2020
2.17.134 3,537 7/28/2020
2.17.133 3,462 7/27/2020
2.17.132 3,469 7/18/2020
2.17.131 3,692 7/11/2020
2.16.130 3,300 6/13/2020
2.15.128 3,542 6/3/2020
2.15.127 3,450 5/31/2020
2.15.126 4,420 4/30/2020
2.14.122 3,228 4/13/2020
2.13.100 3,396 3/12/2020
2.12.51 3,413 2/18/2020
2.11.50 7,499 2/10/2020
2.10.44 8,923 1/30/2020
2.9.43 8,919 1/11/2020
2.8.42 8,923 1/10/2020
2.8.41 8,890 1/5/2020
2.7.40 8,694 1/2/2020
2.7.39 8,609 1/2/2020
2.7.38 8,984 1/1/2020
2.6.37 8,820 12/23/2019
2.6.35 9,082 12/4/2019
2.6.1 8,872 12/2/2019
2.6.0 8,680 11/28/2019
2.5.2 9,221 11/26/2019
2.5.1 8,831 11/12/2019
2.5.0 8,581 11/9/2019
2.4.3 9,104 10/16/2019
2.4.2 8,614 10/16/2019
2.4.1 8,826 9/20/2019
2.3.113 1,770 3/6/2021
2.3.112 1,704 3/6/2021
2.3.28 8,672 9/19/2019
2.3.27 8,801 8/30/2019
2.3.26 8,804 8/20/2019
2.3.25 8,625 8/12/2019
2.3.22 8,754 7/31/2019
2.3.21 8,663 7/20/2019
2.3.20 8,271 6/22/2019
2.3.19 8,751 6/14/2019
2.3.18 8,782 6/13/2019
2.3.17 8,838 6/13/2019
2.3.15 8,391 6/8/2019
2.3.14 8,606 6/8/2019
2.3.13 8,650 5/30/2019
2.3.12 4,191 5/24/2019
2.3.11 4,085 5/24/2019
2.3.10 4,116 5/21/2019
2.3.9 3,908 5/9/2019
2.3.8 4,319 5/8/2019
2.3.7 4,154 4/30/2019
2.3.6 4,262 4/23/2019
2.3.5 4,214 4/19/2019
2.3.4 4,129 4/18/2019
2.3.3 4,105 4/17/2019
2.3.2 4,279 4/6/2019
2.3.1 4,256 12/15/2018
2.3.0 4,271 12/7/2018
2.2.7 3,387 11/30/2018
2.2.6 4,466 11/25/2018
2.2.5 3,660 11/23/2018
2.2.4 3,505 11/22/2018
2.2.3 2,723 11/21/2018
2.2.2 2,563 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