我正在尝试使用蛋糕模式进行依赖注入,如下所示:
trait FooComponent {
val foo: Foo
trait Foo;
}
trait AlsoNeedsFoo {
this: FooComponent =>
}
trait RequiresFoo {
this: FooComponent =>
val a = new AlsoNeedsFoo with FooComponent{
val foo: this.type#Foo = RequiresFoo.this.foo
}
}
但编译器抱怨RequiresFoo.this.type#Foo不符合预期的类型this.type#Foo。
所以问题是:是否可以在AlsoNeedsFoo内部创建一个对象RequiresFoo以便依赖注入正常工作?