Giter VIP home page Giter VIP logo

business.core's Introduction

Platform

.Net Standard 2.0

Depend

Castle.Core

Install

NuGet Version NuGet Badge

PM> Install-Package Business.Core

Please refer unit test

Preface: This library is not RPC, WebAPI, MVC, REST, Http, Rabbitmq, Socket, Kestrel.

What can he do?

This library has the following functions

1: Call Method with a fixed routing, including grouping mode

2: A Process for Processing Parameters

3: A standard return object wrapper

This library has the following characteristics

1: Callbacks for method calls

2: Support object-to-parameter injection

3: A Model for Documentation

4: async Keyword Support

You can use any communication layer you like, such as ASP.Net Core MVC, WebAPI, Sockets, or even UI logic. It can dramatically improve the readability and specifications of your business logic.

Welcome Pull out to branch, but if you have a good idea, I hope it will be discussed thoroughly before you take action.

This library does not support AOT compilation mode, but can run on Xamarin.Android.

Before you begin, you should be familiar with 1 interface definitions

public interface IResult
{
    /// <summary>
    /// The results of the state is greater than or equal 
    /// to 1: success, equal to 0: system level exceptions, less than 0: business class error.
    /// </summary>
    System.Int32 State { get; }

    /// <summary>
    /// Success can be null
    /// </summary>
    System.String Message { get; }

    /// <summary>
    /// Specific Byte/Json data objects
    /// </summary>
    dynamic Data { get; }

    /// <summary>
    /// Whether there is value
    /// </summary>
    System.Boolean HasData { get; }
}

Begin use

1: Define some processing features, if there are multiple, they are sorted by state

public class JsonArg : ArgumentAttribute
{
    public JsonArg(int state = -12, string message = null, bool canNull = false) : base(state, message, canNull) { }

    public Newtonsoft.Json.JsonSerializerSettings Settings { get; set; }

    public override async ValueTask<IResult> Proces(dynamic value)
    {
        try
        {
            return this.ResultCreate(Newtonsoft.Json.JsonConvert.DeserializeObject(value, this.Meta.MemberType, Settings));
        }
        catch { return this.ResultCreate(State, Message ?? $"Arguments {this.Meta.Member} Json deserialize error"); }
    }
}

public class CheckNull : ArgumentAttribute
{
    public CheckNull(int state = -800, string message = null) : base(state, message, false) { }

    public override async ValueTask<IResult> Proces(dynamic value)
    {
        if (object.Equals(null, value))
        {
            return this.ResultCreate(State, Message ?? $"argument \"{Alias}\" can not null.");
        }

        return this.ResultCreate();
    }
}

2: Define your business class

public class BusinessMember : BusinessBase
{
    [JsonArg]
    public struct Dto
    {
        [CheckNull]
        public string A { get; set; }
    }

    public virtual async Task<dynamic> MyLogic(Dto arg)
    {
        return this.ResultCreate(arg.A);
    }
}

3: Register your business class

static BusinessMember Member = Bootstrap.Create<BusinessMember>()
            .Build();

        Bootstrap.Create()
            .Build();

4: Calling business methods

Member.Command.AsyncCall("MyLogic", new object[] { "{\"A\":\"abc\"}" });

See Unit Testing for more features

business.core's People

Contributors

dependabot[bot] avatar xlievo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ezhiyu126 nndude

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.