Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Replace lateinit binding of dependencies with constructor-injection #1292

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version '0.6.0'
buildscript {
ext {
kotlin_version = '1.0.3'
springBootVersion = '1.3.6.RELEASE'
springBootVersion = '1.4.0.RELEASE'
jacksonVersion = '2.8.0'
}

Expand Down
11 changes: 2 additions & 9 deletions src/main/kotlin/ink/abb/pogo/scraper/PokemonGoBotApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import kotlin.concurrent.thread
@SpringBootApplication
open class PokemonGoBotApplication {

@Autowired
lateinit var authProvider: ApiAuthProvider

@Bean
open fun httpClient(): OkHttpClient {
val builder = OkHttpClient.Builder()
Expand All @@ -50,7 +47,7 @@ open class PokemonGoBotApplication {
}

@Bean
open fun interceptorConfigurer(): WebMvcConfigurer {
open fun interceptorConfigurer(authProvider: ApiAuthProvider): WebMvcConfigurer {
return object : WebMvcConfigurerAdapter() {
override fun addInterceptors(registry: InterceptorRegistry) {
registry.addInterceptor(authProvider)
Expand All @@ -61,12 +58,8 @@ open class PokemonGoBotApplication {
}

@Component
open class BotRunner : CommandLineRunner {
@Autowired
lateinit var http: OkHttpClient
open class BotRunner(val http: OkHttpClient, val botRunService: BotService) : CommandLineRunner {

@Autowired
lateinit var botRunService: BotService

override fun run(vararg args: String?) {
val JSONConfigBotNames = botRunService.getJSONConfigBotNames()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ import javax.servlet.http.HttpServletResponse
@RestController
@CrossOrigin
@RequestMapping("/api")
class BotController {

@Autowired
lateinit var service: BotService

@Autowired
lateinit var authProvider: ApiAuthProvider
class BotController (val service: BotService, val authProvider: ApiAuthProvider) {

@RequestMapping("/bots")
fun bots(): List<Settings> {
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/ink/abb/pogo/scraper/services/BotService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import javax.annotation.PreDestroy
import kotlin.concurrent.thread

@Service
class BotService {
class BotService (val http: OkHttpClient) {

@Autowired
lateinit var http: OkHttpClient

private val bots: MutableList<Bot> = mutableListOf()
val settingsJSONWriter = SettingsJSONWriter()
Expand Down
5 changes: 1 addition & 4 deletions src/main/kotlin/ink/abb/pogo/scraper/util/ApiAuthProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

@Component
open class ApiAuthProvider : HandlerInterceptorAdapter() {

@Autowired
lateinit var service: BotService
open class ApiAuthProvider (val service: BotService) : HandlerInterceptorAdapter() {

val random: SecureRandom = SecureRandom()

Expand Down