我想根据我的方法调用的参数动态注入一个类
我尝试使用AspectJ和Spring的不同注释
我需要这样的解决方案:
@Component
class MyUseCase(private val spi: MySpiPort) {
fun myAction() {
spi.doSomething("myId")
}
}
interface Injectable
interface MySpiPort : Injectable {
fun doSomething(id: String)
}
class MyProxyClass {
//will intercept all Injectable
fun resolver(id: String): MySpiPort {
if(id == "myId"){
//inject MyFirstImpl
}else{
//inject MySecondImpl
}
TODO("not implemented")
}
}
@Component
class MyFirstImpl : MySpiPort {
override fun doSomething(id: String) {
TODO("not implemented")
}
}
@Component
class MySecondImpl : MySpiPort {
override fun doSomething(id: String) {
TODO("not implemented")
}
}
我希望仅注入实现的通用接口,而不希望在MyUseCase类中注入FactoryBean类或类似的东西。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句