C# 和 Java 对象的共享业务规则
我有一个包含 Java 服务器端对象和 C# 客户端对象的系统。这些对象可以在系统的两侧进行修改,因此可以附加业务规则。目前的问题是业务规则仅存在于服务器端,我真的希望避免每次想要验证对象时都必须联系服务器。
因此,理想情况下,我希望拥有可在 C# 和 Java 中使用的共享业务规则,因此当需要更改时,我只将其应用到一个地方(显然部署在 2 个地方)。
有人对我如何解决这个问题有任何建议吗?
I've got a system that has Java server side objects and C# client objects. The objects can be modified in both sides of the system and so have business rules attached to them. The thing is currently the business rules only live on the server side, and I really want to avoid having to contact the server every time I want to verify the objects.
So ideally I want to have shared business rules that can be used in both C# and Java, so when a change is required I only apply it in one place (and obviously deploy in 2).
Has anyone any suggestions on how I could go about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
乍一听这可能很糟糕,但实际上您可以考虑用 JavaScript 编写业务规则。
java 和 .NET 平台上都有可用的 JavaScript 引擎。这样,通过在服务器 (java) 和客户端 (C#) 上托管(不同的)javascript 引擎,它们都可以执行相同的 javascript 来强制执行业务规则。
将其视为您选择的业务规则语言。对于这项任务来说,这也是一个不错的选择,因为它简洁、灵活且众所周知。
我曾经做过类似的事情,在基于 java 的游戏中设置灵活的游戏规则。 Javascript 引擎的设置非常简单,而且现在它们的速度也变得相当快。
This may sound terrible at first, but you could in fact consider coding the business rules in javascript.
There are javascript engines available both on the java and .NET platform. That way, by hosting a (different) javascript engine both on the server (java) and client (C#), they can both execute the same javascript to enforce business rules.
Think of it as your business rules language of choice. It's not a bad choice for the task either, as it is terse, flexible and well known.
I have done something similar once, to set up flexible game rules in a java-based game. Javascript engines are surprisingly simple to set up, and nowadays they're getting pretty fast too.
尝试使用 IKVM
Try using IKVM