用Spring + Kotlin声明不可变的构造函数注入(inject)类的正确方法是什么?目前我有:
@RestController
public class AuthorizationController
{
@Inject
lateinit var facebookAuth: FacebookAuthorizationService //Mutable?
@RequestMapping("/authorization")
public fun authorization(@RequestParam(value = "network-type", defaultValue = "Facebook") name: String,
@RequestParam(value = "oauth-token") oauthToken: String,
@RequestParam(value = "oauth-token-secret",
required = false) oauthTokenSecret: String?): Authorization
{
//TODO: Handle other network types
return facebookAuth.authorization(oauthToken)
}
}
我希望facebookAuth属性是不可变的。
最佳答案
这里对Kotlin的经验不多,但我认为必须与
public class AuthorizationController @Inject constructor(private val facebookAuth: FacebookAuthorizationService) {
...
}