Comments (3)
因为在计划中,这些包分为3类:
HandyIpc
提供基础功能,是必须要安装的(其实安装其它包,也会自动带上,可以不需要手动安装);- 通讯层:目前提供了
NamedPipe
和Socket
两种类型,你可以自己选择,只需要一种就好; - 序列化层:目前仅提供 Json,但其实还有 MessagePack、MemoryPack、protobuf ... 等很多序列化器,都可以接入。
事实上,这个库真正的核心功能(必须存在的),就只有一个 HandyIpc
:就是根据 interface
自动生成客户端和服务端的调用代码。至于如何通讯,如何序列化,都是可以自定义的。
而你现在看到的 NamedPipe
, Socket
, Json
这3个包,全是依赖 HandyIpc
提供的 API 实现的,它们并不特殊,你也可以只安装一个 HandyIpc
,然后自己实现一个一样的,只不过比较常用,所以顺便实现了一下,它们本质上不是“必须”存在的。
简单来说,就是“解耦”,你说的问题,我考虑过,因为我也觉得3个包装的有点麻烦,一开始就是一个包的,这就是代码设计的“纯粹性”与“易用性”之间的冲突,我最终还是选择了前者。
from handyipc.
就比如说,你现在只想用 NamedPipe
,那就不必引用 Socket.dll
。
再说序列化,其实不管是现在的 Json,还是以后要加的其它序列化功能,都不是我实现的,都要依赖第三方库(现在 Json 是依赖 Newtonsoft.Json
)。
如果全打包在一起,假如你觉得 Json 性能又慢、数据又大,然后选择了 MemoryPack 来序列化。那么,你也不希望自己的项目里还引用着一个Newtonsoft.Json.dll
吧?
from handyipc.
感谢作者非常详细的解答。
确实鱼和熊掌不可兼得,但是成年人不做选择。
我确实也很讨厌我的软件中有多余的东西存在。
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
}
对于NamedPipe
和Socket
我觉得放在HandyIpc
并无伤大雅,你觉得呢?
唯一的问题就是这样子改动很大了。
from handyipc.
Related Issues (18)
- 开启可控引用类型特性(#nullable enable)后,生成的代码中包含错误的语句:typeof(object?)
- 语法分析无法识别所有形式的 [IpcContractAttribute]
- 支持在 rpc 方法中使用回调函数 HOT 1
- IpcContract 接口支持 IDisposable 接口
- 为所有 public api 添加注释
- 合同接口(IpcContract)支持事件 HOT 1
- 完善测试用例
- ArgumentException: Could not cast or convert from System.String to System.Type. HOT 6
- 如果断开client 之后, server 就会占用大量CPU HOT 6
- The bytes is not valid response data. HOT 4
- 长时间运行会出现 attempted to read or write protected memory HOT 7
- 在Net6环境下,Client关闭后,服务占用的CPU居高不下 HOT 3
- 是否可以尝试去掉System.ValueTuple? HOT 2
- 内存是否哪里没有释放干净? HOT 2
- 使用Named Pipe模式,我如何确认服务端是否开启? HOT 5
- Error running example from README.md HOT 2
- 能否支持 直接注册实例, 现在只能注册类型。 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from handyipc.