我想知道是否可以从包装特征中混合自我类型
例如:
trait PolicyHolderDAOComponent { this: DbConfig with ActorSystemConfig =>
//want to use the injected DbConfig and ActorSystemConfig for instantiation of policyHolderDAO
def policyHolderDAO = new PolicyHolderDAO
class PolicyHolderDAO { this: DbConfig with ActorSystemConfig =>
...
}
}
答案 0 :(得分:3)
给this
一个不同的名称,然后你可以从内部类引用它:
trait PolicyHolderDAOComponent { self: DbConfig with ActorSystemConfig =>
def policyHolderDAO = new PolicyHolderDAO
class PolicyHolderDAO { this: DbConfig with ActorSystemConfig =>
// use self
}
}
请注意,self
的类型均为DbConfig
和ActorSystemConfig
。