【问题标题】:Two dlls (service and interface). Using interface methods to various projects?两个 dll(服务和接口)。对各种项目使用接口方法?
【发布时间】:2013-04-09 13:57:44
【问题描述】:

我有一个相当大的网络应用程序,其中包含几个不同的项目。我必须添加一些额外的功能(帐户验证、搜索产品等)。我得到了两个.dll 文件,比如说Services.dllInterfaces.dll

Services.dll 包括三个类,其中包含多个方法和Interfaces.dll 接口。

例子:

//SERVICES.DLL
using Interfaces;

namespace Services
{
  internal class User : IUser
  {
    public Users GetUserByName (string Name)
    {
      //Implementation
    }
  }
}

//INTERFACES.DLL
namespace Interfaces
{
  public interface IUser
  {
    Users GetUserByName(string Name);
  }

  public class Users
  {
    public string FirstName {get; set;}
    public string LastName {get; set;}
  }
}

为了实现额外的功能,我需要在我包含的几个项目中使用这些方法。如何使用提供的 dll 来实现这一点?使用 dll 创建 Web 服务是一种方式吗?那么服务将如何消费它们呢?

一切都在 C# 和 Net 2.0 中实现。

【问题讨论】:

    标签: c# .net web-services web-applications dll


    【解决方案1】:

    我说这取决于这些 dll 的更新频率。您应该选择更方便更新的任何方法。 Web 服务可能很容易更新,但可能会向您的应用程序添加不必要的层,并且可能会受到带宽限制。您可以考虑直接在您的网络应用程序中添加 dll 文件作为对文件的引用。然后用新版本更新 dll 需要重新构建/重新发布。

    【讨论】:

    • 好的,我想我会添加使用它们作为参考。我现在的问题是我将如何访问和使用 Services.dll 的方法,因为例如 User 类被声明为内部?
    • @istar internal 根据定义只能在同一个程序集中访问,因此除非可以通过IUser 访问这些方法,否则您不能访问。 User GetUserByName(string Name); 也不起作用,因为它返回一个 User - 它应该返回一个 IUser 才能访问。
    • 我更正了上面的代码。 GetUserByName 返回一个 UsersUsersInterfaces.dll 中声明。
    猜你喜欢
    • 2015-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多