GithubHelp home page GithubHelp logo

Comments (3)

DingpingZhang avatar DingpingZhang commented on July 20, 2024

因为在计划中,这些包分为3类:

  1. HandyIpc 提供基础功能,是必须要安装的(其实安装其它包,也会自动带上,可以不需要手动安装);
  2. 通讯层:目前提供了 NamedPipeSocket 两种类型,你可以自己选择,只需要一种就好;
  3. 序列化层:目前仅提供 Json,但其实还有 MessagePack、MemoryPack、protobuf ... 等很多序列化器,都可以接入。

事实上,这个库真正的核心功能(必须存在的),就只有一个 HandyIpc:就是根据 interface 自动生成客户端和服务端的调用代码。至于如何通讯,如何序列化,都是可以自定义的。

而你现在看到的 NamedPipe, Socket, Json 这3个包,全是依赖 HandyIpc 提供的 API 实现的,它们并不特殊,你也可以只安装一个 HandyIpc,然后自己实现一个一样的,只不过比较常用,所以顺便实现了一下,它们本质上不是“必须”存在的。

简单来说,就是“解耦”,你说的问题,我考虑过,因为我也觉得3个包装的有点麻烦,一开始就是一个包的,这就是代码设计的“纯粹性”与“易用性”之间的冲突,我最终还是选择了前者。

from handyipc.

DingpingZhang avatar DingpingZhang commented on July 20, 2024

就比如说,你现在只想用 NamedPipe,那就不必引用 Socket.dll

再说序列化,其实不管是现在的 Json,还是以后要加的其它序列化功能,都不是我实现的,都要依赖第三方库(现在 Json 是依赖 Newtonsoft.Json)。

如果全打包在一起,假如你觉得 Json 性能又慢、数据又大,然后选择了 MemoryPack 来序列化。那么,你也不希望自己的项目里还引用着一个Newtonsoft.Json.dll 吧?

from handyipc.

ping9719 avatar ping9719 commented on July 20, 2024

感谢作者非常详细的解答。
确实鱼和熊掌不可兼得,但是成年人不做选择。
我确实也很讨厌我的软件中有多余的东西存在。

namespace ThreeYardsBin
{
    #region HandyIpc
    //序列化接口
    public interface ISerialize
    {
        //序列化
        object Serialize(string json);
        //反序列化
        string Serialize(object jsonObj);
    }

    //内部使用方式(采用net自带的序列化)
    public class NetSerialize : ISerialize
    {
        public object Serialize(string json) => null;
        public string Serialize(object jsonObj) => null;
    }

    //HandyIpc 中的发送,接受。用到了序列化
    public class HandyIpc
    {
        public static ISerialize Serialize = new NetSerialize();
        public void Send(object obj)
        {
            string info = Serialize.Serialize(obj);
        }
    }
    #endregion

    #region 用户

    //用户实现接口,采用Newtonsoft.Json方式
    public class JsonSerialize : ISerialize
    {
        public object Serialize(string json) => null;
        public string Serialize(object jsonObj) => null;
    }

    //用户可以自定义序列化
    public class User
    {
        public void ABC()
        {
            HandyIpc.Serialize = new JsonSerialize();

            HandyIpc handyIpc = new HandyIpc();
            handyIpc.Send(new { });
        }
    }
    #endregion
}

对于NamedPipeSocket我觉得放在HandyIpc并无伤大雅,你觉得呢?
唯一的问题就是这样子改动很大了。

from handyipc.

Related Issues (18)

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.