package be.vandewalleh import be.vandewalleh.auth.AuthenticationModule import be.vandewalleh.auth.SimpleJWT import be.vandewalleh.controllers.api.ApiNoteController import be.vandewalleh.controllers.api.ApiTagController import be.vandewalleh.controllers.api.ApiUserController import be.vandewalleh.controllers.web.BaseController import be.vandewalleh.controllers.web.NoteController import be.vandewalleh.controllers.web.UserController import be.vandewalleh.extensions.ApplicationBuilder import be.vandewalleh.extensions.RoutingBuilder import be.vandewalleh.factories.* import be.vandewalleh.features.* import be.vandewalleh.markdown.Markdown import be.vandewalleh.repositories.NoteRepository import be.vandewalleh.repositories.UserRepository import be.vandewalleh.routing.api.ApiDocRoutes import be.vandewalleh.routing.api.ApiNoteRoutes import be.vandewalleh.routing.api.ApiTagRoutes import be.vandewalleh.routing.api.ApiUserRoutes import be.vandewalleh.routing.web.BaseRoutes import be.vandewalleh.routing.web.NoteRoutes import be.vandewalleh.routing.web.StaticRoutes import be.vandewalleh.routing.web.UserRoutes import com.soywiz.korte.TemplateProvider import com.soywiz.korte.Templates import io.ktor.features.* import org.kodein.di.* import org.kodein.di.DI import org.slf4j.LoggerFactory val mainModule = DI.Module("main") { bind() from singleton { NoteRepository(instance()) } bind() from singleton { UserRepository(instance(), instance()) } bind() from singleton { configurationFactory() } bind() from setBinding() bind().inSet() with singleton { ErrorHandler(instance()) } bind().inSet() with singleton { ContentNegotiationFeature() } bind().inSet() with singleton { CorsFeature(instance().server.cors) } bind().inSet() with singleton { AuthenticationModule(instance(tag = "auth")) } bind().inSet() with singleton { MigrationHook(instance()) } bind().inSet() with singleton { ShutdownDatabaseConnection(instance()) } bind().inSet() with singleton { SecurityReport() } bind().inSet() with singleton { CachingHeadersFeature() } bind().inSet() with singleton { CompressionFeature() } bind().inSet() with singleton { CallLoggingFeature() } bind() from setBinding() bind().inSet() with singleton { ApiDocRoutes() } bind().inSet() with singleton { ApiNoteRoutes(instance()) } bind().inSet() with singleton { ApiTagRoutes(instance()) } bind().inSet() with singleton { ApiUserRoutes(instance()) } // API bind() from singleton { ApiNoteController(instance(), instance()) } bind() from singleton { ApiTagController(instance()) } bind() from singleton { ApiUserController( userRepository = instance(), authJWT = instance(tag = "auth"), refreshJWT = instance(tag = "refresh"), passwordHash = instance() ) } // web bind().inSet() with singleton { BaseRoutes(instance()) } bind().inSet() with singleton { UserRoutes(instance()) } bind().inSet() with singleton { NoteRoutes(instance()) } bind().inSet() with singleton { StaticRoutes() } bind() from singleton { NoteController(instance(), instance(), instance()) } bind() from singleton { BaseController(instance()) } bind() from singleton { UserController( userRepository = instance(), authJWT = instance(tag = "auth"), templates = instance(), passwordHash = instance() ) } bind() with singleton { ResourceTemplateProvider() } bind() with singleton { templatesFactory(instance()) } bind(tag = "auth") with singleton { simpleJwtFactory(instance().jwt.auth) } bind(tag = "refresh") with singleton { simpleJwtFactory(instance().jwt.refresh) } bind() from singleton { LoggerFactory.getLogger("Application") } bind() from singleton { dataSourceFactory(instance().database) } bind() from singleton { databaseFactory(instance()) } bind() from singleton { Migration(instance()) } bind() with singleton { BcryptPasswordHash() } bind() from singleton { Markdown() } }