سؤال

I want to declare an enum in my ASP.NET Web API project, a member of which will be passed from the Controller to the Repository, a la:

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

Controller

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

Repository

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

Where would be the best place to declare this enum - in a new class? In Global.asax.cs? Somewhere else?

Note: I do realize that the "right" way to do it might be to create multiple implementations of the interface implementation, one that will save to Access, another to SQLite, etc.

هل كانت مفيدة؟

المحلول

I think the best way for enums in ASP.NET MVC project is DataAccess directory:

  • DataAccess project
    • Base
    • Entities
    • Enums
    • Repositories
    • ...
  • Site project
    • Controllers
    • Models
    • Views
    • Services
    • ...
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top