1

我正在寻找构建一个小应用程序来与 C# 中的 ruby​​ msgpack 服务器通信。到目前为止,我唯一的问题是服务器后面的 API 期望提取一个 ruby​​ 哈希。我可以在 C# 中使用简单的字典/键值对类型吗?如果没有,你有什么建议?

我将使用 msgpack 网站 (http://wiki.msgpack.org/display/MSGPACK/QuickStart+for+C+Sharp) 上提到的库。但是,它似乎只支持原始类型?我尝试过使用 IronRuby 的方式,但是 mono 中有一个非常严重的错误,它会阻止你使用它。https://bugzilla.xamarin.com/show_bug.cgi?id=2770

4

1 回答 1

0

It is normal that different part of the system can be built using different technology stacks. Because these parts should be able to talk to each other (this way or another) it is important to specify contracts between subsystems.

It is really important to think first about these contracts as these parts of your system (subsystems) can be (and will be, no doubt) subjects of changes (due to evolving their business logic, bug fixes, etc.).

By having these contracts you allow subsystems to be changed independently without impacting all their "clients" (other subsystems). Otherwise you will end up with "I need to fix this, but may affect tonnes of places I even don't know about" syndrome.

Well, as soon as you hold the contract you can do whatever you want within the given subsystem, which is just a Heaven! :)

This means that instead of "pulling out the ruby hash" you normally want to define a platform-agnostic contract that will be exposed as an aspect in terms of the business logic of your application. This contract then can be consumed by any other subsystem written in any technology.

It also means that instead of just passing some data between subsystems you want to pass some objects. These objects not only contain the data you want to pass, but also describe this data, dive it some meaning. By this "description" I mean the object type, property names, ect. Objects are self-descriptive, you know.

You may declare the contract for your ruby subsystem saying "I accept these queries and I return these results". Both query (method) and result (object) should be formulated in terms of business logic of the specified subsystem. For example, GetProducts contract should probably return a list of Product objects, not some meaningless "ruby hashes". So all the consumers will know what the contract is and what to expect.

You can make it a standard then, saying "between subsystems all the objects passed are serialized to JSON (or XML)", which is more than trivial in Ruby, C# or any other language, as well as truly platform-agnostic.

Therefore, back to your question, you normally just have no such problem in your live as translating ruby types into .NET types using some buggy libraries, or doing similar crazy things :)

Simply defining contracts and standardizing transport (JSON?) helps you in many ways starting from getting rid of this problem and all the way through to having the clean and easily maintainable system.

于 2012-02-18T03:53:40.327 回答