服务接口 - 几种方法的比较

发布于 2024-12-05 06:32:39 字数 1141 浏览 2 评论 0原文

我很难确定哪种方法更好:

interface IService {
  ISomething CreateSomething();
}

interface ISomething {
  void Do(string parameter);
}

vs

interface IService {
  ISomething CreateSomething();
  void DoSomething(ISomething something, string parameter);
}

vs vs

interface IService {
  ISomething CreateSomething();
  void DoSomething(int somethingId, string parameter)
}

vs

interface IService {
  int CreateSomething(); // returns something.Id
  void DoSomething(int somethingId, string parameter);
}

vs vs任何其他方法...

iservice接口应该以多种不同的方式消费:

  • 作为类库
  • 作为一个类库WCF服务
  • 作为XML服务
  • 作为JSON服务

Isomething可能具有客户需要调查的许多属性,并且可能执行许多操作。 Isomething只是我需要以这种方式公开的十几个类之一。 isomething可能会返回更多我可以执行操作的接口。

我将感谢任何建议和思想。

编辑:

这个想法是创建一个服务,该服务将允许用户构建工作流程图,并将支持设计师。我的要求是具有支持客户端任何风味的服务代码(因此int参数方法)。同时,我不想遇到类型和方法的爆炸。

也许最好的方法是将其设计为功能丰富的.NET库,并为任何可能消耗的渠道创建外墙(?)?

I'm having a hard time deciding which approach is better:

interface IService {
  ISomething CreateSomething();
}

interface ISomething {
  void Do(string parameter);
}

vs

interface IService {
  ISomething CreateSomething();
  void DoSomething(ISomething something, string parameter);
}

vs

interface IService {
  ISomething CreateSomething();
  void DoSomething(int somethingId, string parameter)
}

vs

interface IService {
  int CreateSomething(); // returns something.Id
  void DoSomething(int somethingId, string parameter);
}

vs any other...

The IService interface is supposed to be consumed in a number of different ways:

  • As a class library
  • As a WCF Service
  • As an XML Service
  • As a JSON Service

ISomething may have a number of properties that the client will want to investigate, and a number of operations it may perform. ISomething is just one of dozen classes I need to expose this way. ISomething may return more interfaces that I can perform operations on.

I will appreciate any and suggestions and thoughts.

EDIT:

The idea is to create a service that will allow the users to build a workflow graph, and will support a designer. My requirements are to have service code that will support any flavor of a client (therefore the int parameter approaches). At the same time I don't want to run into an explosion of types and method.

Maybe the best approach would be to design it as a feature rich .NET library, and create facades (?) for any channels that may be consuming that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我鬧 2024-12-12 06:32:39

我会使用:

interface IService {
  ISomething CreateSomething();
  void DoSomething(int somethingId, string parameter)
}

恕我直言,它会产生最少的流量,因为如果您只是从 CreateSomething 返回 ID,如果您需要处理详细信息,您很可能会再进行一次旅行。

DoSomething 中使用 id 可以为您提供最少的流量,因为似乎不需要整个对象。

始终尝试设计服务接口,以便您必须使用尽可能少的调用来完成您想要的操作。这也意味着很难告诉你答案,因为我不知道其预期目的。

I would use:

interface IService {
  ISomething CreateSomething();
  void DoSomething(int somethingId, string parameter)
}

imho it would generate least traffic since if you just return ID from CreateSomething you'll most likely do another trip if you need the details for processing.

Using the id in DoSomething gives you the least traffic since the entire object doesn't seem to be necessary.

Always try to design service interfaces so that you have to use a few calls as possible to do what you want. That also means that it's difficult to tell you an answer since I do not know the intended purpose.

心房敞 2024-12-12 06:32:39

我看到的问题是您希望一个类同时成为服务和数据契约。 ISomething 不能是接口,因为您实际上传递了具体类型,并且您的客户端应该知道它们的结构。所以我的建议是服务仍然是服务,数据合同仍然是它本身。

class Something
{
}

interface IService {  
  void Do(string parameter);
  Something GetSomething();
}

class SomeService : IService {
  private Something smth;  

  public void SomeService()
  {
    smth = CreateSomething();
  }

  public void Do()
  {
    //
  }

  public Something GetSomething()
  {
    return smth;
  }
}

The problem I see is that you want for a class to be a service and data contract at the same time. ISomething can't be interface, because you actually pass concrete types and your clients should know their structure. So my suggestion is that service remains service and data contract remains itself.

class Something
{
}

interface IService {  
  void Do(string parameter);
  Something GetSomething();
}

class SomeService : IService {
  private Something smth;  

  public void SomeService()
  {
    smth = CreateSomething();
  }

  public void Do()
  {
    //
  }

  public Something GetSomething()
  {
    return smth;
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文