4 php architecture software-design zend-framework2
There are many components in one ZF2 system. Each component has its own presentation layer, business layer, and data layer. The problem is when component Foo has a Controller which uses component Bar's data layer.
example:
<inside modules, each module can be individually deployed or removed>
\modules
\Foo ; one module (this directory) can be added or removed
\view ; presentation layer (view) for all subcomponents
\Subcomponent1
\Action1
\Subcomponent2
\Action2
...
\src
\Subcomponent1
\Entity ; data layer (model)
\Controller ; business layer (controller)
\Service ; service layer (service)
\Subcomponent2
\Entity
\Controller
\Service
\Subcomponent3
...
\Bar
\view
...
\src
\Subcomponent1
...
\Baz
\src
\Subcomponent1
...
Run Code Online (Sandbox Code Playgroud)
Subcomponents are strongly coupled with Entities from other subcomponents, often from different components entirely. That is the case for Controllers and Services. Can this be resolved?
Foo\Subcomponent1 has a FooSub1Service which uses entity from Bar\Subcomponent1 to process passed data and import them in DB. Baz\Subcomponent1 has an AuthenticationService which uses Bar\Subcomponent1 entities to find user by ID, etc.
我知道依赖注入的,但在这种情况下,有EntityManager的每个子,它是由指示名称和PK找到一个实体,即寻找("律师\ Subcomponent1 \实体\用户",123).而且,当持久化实体时,我必须实例化任何具有外键的东西,即UserAddress并将其添加到用户.每次调用x = new NameOfEntity()时,我都会将子组件与子组件中的某个实体紧密耦合,通常来自不同的系统模块.
小智 7
在ZF2中,模块之间的耦合可以使用EventManager,也可以在这里看到.
此外,还可module/config/module.config.php作为Facade.
所有实体可以定义ONCE任何模块的module/config/module.config.php文件.然后,其他模块可以使用它ServiceManager来解析它们的依赖关系.
在ServiceManager实现了Service Locator模式.
使用Facade(module.config.php)EventManager,模块之间的耦合成功减少.
| 归档时间: |
|
| 查看次数: |
1721 次 |
| 最近记录: |