C# Project folder naming conventions

后端 未结 5 1115
轻奢々
轻奢々 2021-02-05 20:19

I have a project called Data which is a data layer. In this project, all files are just lying in the top folder. I have enumerations, POCOs, repositories, partial classes and so

相关标签:
5条回答
  • 2021-02-05 20:31

    A good practice is to name the folder after the name of the project.

    Design Guidelines for Developing Class Libraries has a set of Guidelines for Names

    The last item should be of paticular interest for you:

    • Names of Assemblies and DLLs
    • Names of Namespaces
    • Types and Namespaces
    0 讨论(0)
  • 2021-02-05 20:32

    I tend to use project folders as a way of separating out sub namespaces. So in your case, perhaps a folder called Repositories, which has class in the Data.Repositories namespace. Note, for partial classes, each file needs to be in the same namespace.

    0 讨论(0)
  • 2021-02-05 20:35

    Best prectice is to divide entities in folders by object model meaning, not by type.

    0 讨论(0)
  • 2021-02-05 20:38

    I (currently - changes based on project) tend to use this approach when naming assemblies/projects/namespaces in a SAAS/Web style project)

    • CompanyName.
      • ProductName.
        • Data.
        • Business. (references data)
        • Model. (POCO and interfaces - referenced by all)
        • Services. (WCF service layer)
        • ServiceClient. (referenced by web clients)
        • Web. (web client business layer)
          • ViewModel. (view specific model)
          • {client facing product segment} [Commerce, CMS, CRM, Reporting, etc.]

    To explain the Services/Service Client...I use an IoC (currently StructureMap) that allows my WebClient to either speak directly to the Business layer or to be redirected to speak through the ServiceClient through Services to the Business layer. This gives me the flexibility to either deploy my app layer to my web applications or to distribute pieces of my business layer (app layer) to different servers by way of WCF/SOA principles.

    0 讨论(0)
  • 2021-02-05 20:52

    If it is not clear how to group the classes by usage or object model meaning, just leave them all in one folder. Using subfolders don't give values if they don't organise the classes in a meaningful way.

    Dividing folders by type, e.g. enumerations, POCOs, repositories, partial classes etc is not likely to be useful.

    You may wish to use a subfolder for generated code that should not be edited.

    Also remember you can have folders within the solution explorer that are not part of the file system. Given how costly (in time) it is in some source code control systems to move files between directories, I would consider starting of just using msdev folders until you are clear on the structure you want.

    There is no need to put each enumeration in its own file, if an enumeration is only used by one class, it is valid to put it in the same file as the class. E.g the PersonSex enumeration can be put in the person.cs file. Likewise if you have a lot of small and closely related classes, consider putting them in the same file.

    0 讨论(0)
提交回复
热议问题