可以将代码放在项目的根目录中吗?

发布于 2024-07-08 23:44:51 字数 216 浏览 10 评论 0原文

我正在尝试提出有关项目目录结构的最佳实践。

我最新的想法是项目的根目录中不应该有任何类。 所有类都必须位于以下目录之一下

  • UI
  • BusinessObjects
  • BusinessLogic
  • DataAccess

我想听听其他人的想法是否存在将事物放在根级别或查找不适合的类的用例

I am trying to come up with a best practices on project directory structure.

my latest thought is that there should be no classes in the root directory of a project. All classes must go under one of the following directories

  • UI
  • BusinessObjects
  • BusinessLogic
  • DataAccess

i would like to hear other people thought on if there are use cases for putting things at the root level or find classes that wouldn't fit into

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

夜深人未静 2024-07-15 23:44:51

如果您谈论的是 C#,那么我会将您的 DAL、BLL、GUI 分离到不同的项目而不是一个项目。 并且有一个解决方案。 这将强制每个代码文件位于其中一个项目内。

我添加了一个示例:

  • 解决方案:ProjectName
    • 项目:DAL(命名空间:ProjectName.DAL)
      • 文件夹:Repositories(命名空间:ProjectName.DAL.Repositories)
      • 文件夹:Contracts(命名空间:ProjectName.DAL.Contracts)
      • 文件:您的实体映射配置
    • 项目:BLL(命名空间:ProjectName.BLL)
      • 文件夹:Services(命名空间:Project.BLL.Services)
      • 文件夹:Entities(命名空间:Project.BLL.Entities)
      • 文件:IoC 配置类/常规业务逻辑
    • 项目:共享(命名空间:ProjectName.Shared)
      • 文件:整个应用程序的通用共享逻辑(例如 InvalidIdentifier 常量)
      • 此项目不应引用解决方案中的其他项目。
    • 项目:网站(命名空间:ProjectName.Website)
      • 您的 asp.net 网站用户界面
    • 项目:Winforms(命名空间:ProjectName.Winforms)
      • 您的 winforms 用户界面

如果可能的话,你应该给网站和 winforms 项目一个与你的应用程序相关的名称。

If you're talking about C# then I would separate your DAL, BLL, GUI to different projects instead of one project. And have one solution. This will force each code file to be inside of one of the projects.

I've added an example:

  • Solution: ProjectName
    • Project: DAL (Namespace: ProjectName.DAL)
      • Folder: Repositories (Namespace: ProjectName.DAL.Repositories)
      • Folder: Contracts (Namespace: ProjectName.DAL.Contracts)
      • Files: Your Entity Mapping configuration
    • Project: BLL (Namespace: ProjectName.BLL)
      • Folder: Services (Namespace: Project.BLL.Services)
      • Folder: Entities (Namespace: Project.BLL.Entities)
      • Files: IoC configuration classes/general Business Logic
    • Project: Shared (Namespace: ProjectName.Shared)
      • Files: General shared logic throught your whole application (for instance an InvalidIdentifier constant)
      • This project should not reference other projects in the solution..
    • Project: Website (Namespace: ProjectName.Website)
      • Your asp.net website UI
    • Project: Winforms (Namespace: ProjectName.Winforms)
      • Your winforms UI

If possible you should give the website and winforms project a name relative to your application.

ぇ气 2024-07-15 23:44:51

这个博客应该为您提供一些有趣的读物,尽管已经发布了三年。 除了目录结构之外,它还可能为您提供一些想法。

This blog should provide you with some interesting reading, despite being three years old. It might give you ideas besides those of just directory structure.

酒几许 2024-07-15 23:44:51

我放入根文件夹的唯一文件是 Program.csProgram.ico (如果它是可执行应用程序)。

The only files I put into root folder are Program.cs and Program.ico (if it's executable application).

明天过后 2024-07-15 23:44:51

我不这样做,但它与目录结构无关(对我来说)。 我希望所有代码都位于有意义的命名空间中。

I don't do it, but it has nothing to do with the directory structure (for me). I want all my code in meaningful namespaces.

雾里花 2024-07-15 23:44:51

我总是将项目异常的基类放在根目录中。

I always put the base class for my projects exceptions in the root.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文