Skip to content

希望框架能更完善的几个点 #3544

Answered by huangzhhui
zeroxxmmbm asked this question in Q&A
Discussion options

You must be logged in to vote

在我看来,里面提到的很多观点是还没理解清楚 Hyperf 的设计理念和相关机制 ,而用其它框架的设计理念套用过来所产生的

比如相比之下少了@bean注解没有那么方便,各种要去配置文件配置,自定义注解收集与解析用起来也感觉比较麻烦

这句话提到了3点,首先 @Bean 注解的问题,Bean 仅仅是为了定义给 Inject/Autowire 注解所出现的产物,而在 Hyperf 里的理念是所有类都应该设计成可持久化被注入的,故不存在所谓的 Bean 概念,那剩余的你指的可能是 @Bean(scope="prototype") 的多例场景,这个在一开始设计时是不希望存在的,可以通过 Context 协程上下文代理的形式解决每个类,具体做法可参考 Hyperf\Utils\Traits\StaticInstance,当然也不排除后续会通过注解提供类似的做法;
其次配置这里我理解你所说的应该是两个说法,一是 config/autoload/dependencies.php 配置依赖注入关系,这个是必须存在的,二是 Spring 中通过 @Configuration 注解来替代配置文件的存在,这我认为只不过是为了 OOP 而 OOP,为了注解而注解的做法,在 PHP 中对象配置文件的做法远比不上 PHP 数组配置的灵活性;
最后所提到的自定义注解收集和解析起来使用比较麻烦这点,在 Hyperf 里相比其他框架是简化了注解收集流程的,简化了解析器和收集器的概念,由注解类自身实现自收集,对于注解元数据的使用,实际上是对一个 PHP 数组的使用,这里的简便与否就因人而异了,不过在我看来的…

Replies: 10 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@pro911
Comment options

Answer selected by limingxinleo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@limingxinleo
Comment options

@huangzhhui
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
8 participants
Converted from issue

This discussion was converted from issue #3539 on May 07, 2021 02:52.