Controller中引用service为其成员变量, service定义为prototype类型的.
Controller是Singleton类型的,那么虽然service是定义为prototype,但仍然是单例的,因为Controller在构建的过程中只是调用了一次。而如果想通过此手段获得多例的service肯定是失败的!
那么如何在一个singleton类型的Controller中引入prototype类型的service呢?
可以这样实现:
Controller中引用service为其成员变量, service定义为prototype类型的.
Controller是Singleton类型的,那么虽然service是定义为prototype,但仍然是单例的,因为Controller在构建的过程中只是调用了一次。而如果想通过此手段获得多例的service肯定是失败的!
那么如何在一个singleton类型的Controller中引入prototype类型的service呢?
可以这样实现: