Skip to content

Latest commit

 

History

History
142 lines (110 loc) · 4.14 KB

README.md

File metadata and controls

142 lines (110 loc) · 4.14 KB

NetStitch

Build status

NetStitch is a Http RPC Framework built on .NetFramework/.NETCore.

It is provides simple and easy Http WebApi Call for C#.

This Framework is composed of two projects NetStitch.Server and NetStitch.Client.

NetStitch.Server

NetStitch.Server is a Middleware of ASP.NET Core.

Installation

PM>Install-Package NetStitch.Server

Package Structure

NetStitch.Server Packages
  ├─build
  │  └NetStitch.Server.targets
  └─lib
     └DLLs

NetStitch.Server.targets

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
   <PropertyGroup>
    <DefineConstants>$(DefineConstants);___server___</DefineConstants>
    <NoWarn>1998</NoWarn>
  </PropertyGroup>
</Project>

Usage

1.Add ASP.Net Core StartUp.

public class Startup
{
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseNetStitch(typeof(Startup));
    }
}

2.Implementation of "If Directive Approach" Interface .

    public interface Interface : INetStitchContract
    {
        [Operation]
        ValueTask<int> ValueTaskMethodAsync
        (int a, int b
#if !___server___
        , System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)
#endif
        );
    }
    
    public class MyClass : Interface
    {
        public async ValueTask<int> ValueTaskMethodAsync(int a, int b)
        {
            return a + b;
        }
    }

NetStitch.Client

NetStitch.Client is a RPC Client of NetStitch.Server.

Installation

PM>Install-Package NetStitch.Client

Usage

new NetStitch.NetStitchClient(EndPointUrl).Create<Interface>().Method(Parameter);

Sample

See NetStitch-Sample-CI

Feature

If Directive Approach

NetStitch uses #if preprocessor directive to match the definitions of client and server interfaceses.

Original Method

    public interface Interface
    {
        ValueTask<int> ValueTaskMethodAsync(int a, int b);
    }

If Directive Approach

    public interface Interface : INetStitchContract
    {
        [Operation]
        ValueTask<int> ValueTaskMethodAsync
        (int a, int b
#if !___server___
        , System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)
#endif
        );
    }

Pattern List

ReturnType Original Method If Directive Approach
Task Task MethodAsync();

[Operation]
Task MethodAsync(int a, int b
#if !___server___
, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)
#endif
);
ValueTask<T> ValueTask<int> MethodAsync(int a, int b);

[Operation]
ValueTask MethodAsync(int a, int b
#if !___server___
, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)
#endif
);

Serializer

Request data and Response data are serealize by MessagePack-CSharp(LZ4MessagePackSerializer).

Please try to define the type according to MessagePack-CSharp rules.

Analyzer and CodeFix

NetStitch are Supported Analyzer and Codefix.

Usage

1.Get NetStitch.Analyzer from Nuget.

PM>Install-Package NetStitch.Analyzer

2.Implement INetStitchContract interface in Interface

3.Select NetStitchCodefix menu item codefix

License

NetStitch is licensed under MIT. Refer to LICENSE for more information.

This Project is Inspired by LightNode.