【问题标题】:What is the standard location for global enums in an ASP.NET Web API app?ASP.NET Web API 应用程序中全局枚举的标准位置是什么?
【发布时间】:2014-02-07 18:56:28
【问题描述】:

我想在我的 ASP.NET Web API 项目中声明一个枚举,其中的一个成员将从 Controller 传递到 Repository,a la:

enum SaveTypes
{
MSAccess,
SQLite,
CSV,
XML,
JSON
};

控制器

SaveTypes st = SaveTypes.MSAccess;
_inventoryItemRepository.PostInventoryItem(id, ... st);

存储库

public void PostInventoryItem(string id, ... SaveTypes _st)
{
    if (st == SaveTypes.MSAccess)
    {
    //give it to the fake database
    }
    else if (st == SaveTypes.FoieGrasBar) 
    ...

在哪里声明这个枚举的最佳位置 - 在一个新类中?在 Global.asax.cs 中?其他地方?

注意:我确实意识到“正确”的做法可能是创建接口实现的多个实现,一个将保存到 Access,另一个保存到 SQLite,等等。

【问题讨论】:

  • 在我看来,这完全是个人偏好/本地编码指南问题......你喜欢的任何地方都可以......

标签: c# asp.net-mvc asp.net-web-api enums global-asax


【解决方案1】:

我认为 ASP.NET MVC 项目中枚举的最佳方式是 DataAccess 目录:

  • 数据访问项目
    • 基础
    • 实体
    • 枚举
    • 存储库
    • ...
  • 现场项目
    • 控制器
    • 型号
    • 观看次数
    • 服务
    • ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-10
    • 2019-06-23
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多