【问题标题】:Create Restful Service Using Repository使用存储库创建 Restful 服务
【发布时间】:2017-08-21 06:57:59
【问题描述】:

我有一个 mvc 应用程序。我正在使用存储库模式和依赖注入模式。这是一个简单的界面:

[ServiceContract]
    public interface ICategoryService
    {
        [OperationContract]
        List<Category> GetAll();

        Category Add(Category category);
    }

以及实现这个接口的具体类:

public class CategoryManager : ICategoryService
{
    private readonly ICategoryDal _categoryDal;

    public CategoryManager(ICategoryDal categoryDal)
    {
        _categoryDal = categoryDal;
    }

    public List<Category> GetAll()
    {
        return _categoryDal.GetWithSp();
    }

    public List<Category> GetAll(int a)
    {
        return _categoryDal.GetList();
    }

    public Category Add(Category category)
    {

       return _categoryDal.Add(category);
    }
}

我将这个具体类注入到 global.asax 中的接口。 现在我需要创建一个web服务来暴露这个接口中的一些方法(这个接口只是一个例子。不只是这个)。 我怎么能通过一些努力做到这一点?因为这些方法大部分已经在 Web 应用程序上运行了,所以可能只需要添加一些方法。

我可以将此界面用作合同,而不是创建一个新界面吗?或者当我还需要使用其他接口时该怎么办?

【问题讨论】:

    标签: c# web-services interface


    【解决方案1】:

    你可以使用它! 使用实体框架、通用存储库模式和工作单元的具有 Web API 的企业级应用程序架构。

    using Web Api with generic repository

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-06
      • 1970-01-01
      • 2021-08-21
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多