【问题标题】:Organizing the directory structure of my DDD-based web application?组织我的基于 DDD 的 Web 应用程序的目录结构?
【发布时间】:2011-08-09 18:55:29
【问题描述】:

我已经开始远离创建 Web 应用程序的常规 MVC 方式,并查看了域驱动设计 - DDD。

从单独拥有Models,我现在可以在我的应用程序中使用CollectionsEntitiesDataMappersRepositories。完全成熟的分离和模块化是肯定的,但现在我的目录结构不过是一团糟!

由于我过去从未使用过 DDD 应用程序,因此我不知道如何组织我的文件结构。

以下是合适的目录结构吗?
注意:我使用的是 PHP5,但我认为这个问题与语言无关。

/application
    /common
        /libraries
        /helpers
    /temp
        /cache
    /domain
        /collections
        /entities
        /datamappers
        /repositories
    /ui
        /controllers
        /view

【问题讨论】:

    标签: php domain-driven-design directory-structure


    【解决方案1】:

    我认为这是有道理的,但是,这会将您的模块分成它们所在的层,而不是它们的作用。例如,在这个结构中,如果你想要一个身份验证和打印模块,你可能会有这样的东西:

        /common
            /helpers
                 /Authentication
                     /AuthenticationService.php
                 /Printing
                     /PrintingService.php
        /domain
            /entities
                 /Authentication
                     /Identity.php
                 /Printing
                     /Printer.php
            /datamappers
                 /Authentication
                     /IdentityDataMap.php
                 /Printing
                     /PrinterDataMap.php
    

    在这样的系统中工作过,我可以说,一方面,要防止模块之间的边界相互啮合变得非常困难,因为人类在层中工作,并且将层视为“所有一起'。仅从组织的角度来看,我真的不喜欢必须打开三个根级目录才能使用特定模块。我们将项目组织到目录中,以便我们更容易处理,而不是编译器。

    如果我再做一次,我会逐层分离一些东西,比如 UI 代码,在一个层次上,业务代码在另一个层次上,然后在下面的模块中。我想更像是一个混合体,但也许更好。

        /domain
            /Printing
                /entities
                /datamappers
                /repositories
            /Auth
                /entities
                /datamappers
                /repositories
        /ui
            /controllers
            /view
    

    【讨论】:

    • 你会把你的值对象放在哪里?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    相关资源
    最近更新 更多