or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

application.mdcomponents.mddependency-injection.mdglobal-context.mdindex.mdmodules.mdscopes.md

application.mddocs/

0

# Application Configuration

1

2

Application lifecycle and configuration management for setting up dependency injection in your WASM JS application.

3

4

## Capabilities

5

6

### Application Creation

7

8

Creates a new Koin application with optional configuration.

9

10

```kotlin { .api }

11

/**

12

* Creates a new KoinApplication with optional eager instance creation and configuration

13

* @param createEagerInstances - Whether to create eager instances immediately (default: true)

14

* @param appDeclaration - Optional DSL configuration block

15

* @return KoinApplication instance for further configuration

16

*/

17

fun koinApplication(createEagerInstances: Boolean = true, appDeclaration: KoinAppDeclaration? = null): KoinApplication

18

19

/**

20

* Creates a new KoinApplication with DSL configuration

21

* @param appDeclaration - DSL configuration block

22

* @return KoinApplication instance

23

*/

24

fun koinApplication(appDeclaration: KoinAppDeclaration?): KoinApplication

25

26

/**

27

* Creates a new KoinApplication from existing configuration

28

* @param configuration - Pre-built configuration

29

* @return KoinApplication instance

30

*/

31

fun koinApplication(configuration: KoinConfiguration?): KoinApplication

32

33

/**

34

* Creates a new KoinApplication with eager instance creation flag

35

* @param createEagerInstances - Whether to create eager instances immediately

36

* @return KoinApplication instance

37

*/

38

fun koinApplication(createEagerInstances: Boolean): KoinApplication

39

```

40

41

**Usage Examples:**

42

43

```kotlin

44

import org.koin.dsl.koinApplication

45

import org.koin.dsl.module

46

47

// Basic application creation

48

val app = koinApplication()

49

50

// Application with configuration

51

val app = koinApplication {

52

modules(appModule)

53

logger(PrintLogger())

54

}

55

56

// Application without eager instances

57

val app = koinApplication(createEagerInstances = false) {

58

modules(appModule)

59

}

60

```

61

62

### KoinApplication Class

63

64

Main application class for configuration and lifecycle management.

65

66

```kotlin { .api }

67

class KoinApplication {

68

/** Access to the underlying Koin container */

69

val koin: Koin

70

71

/** Load a single module into the application */

72

fun modules(modules: Module): KoinApplication

73

74

/** Load multiple modules into the application */

75

fun modules(vararg modules: Module): KoinApplication

76

77

/** Load a list of modules into the application */

78

fun modules(modules: List<Module>): KoinApplication

79

80

/** Create all eager instances immediately */

81

fun createEagerInstances()

82

83

/** Allow definition overrides in modules */

84

fun allowOverride(override: Boolean)

85

86

/** Load properties into the application */

87

fun properties(values: Map<String, Any>): KoinApplication

88

89

/** Set configuration options */

90

fun options(vararg optionValue: Pair<KoinOption, Any>): KoinApplication

91

92

/** Set a custom logger implementation */

93

fun logger(logger: Logger): KoinApplication

94

95

/** Set a print logger with specified level */

96

fun printLogger(level: Level = Level.INFO): KoinApplication

97

98

/** Close the application and cleanup resources */

99

fun close()

100

101

companion object {

102

/** Create a new KoinApplication instance */

103

fun init(): KoinApplication

104

}

105

}

106

```

107

108

**Usage Examples:**

109

110

```kotlin

111

import org.koin.core.KoinApplication

112

import org.koin.core.logger.Level

113

import org.koin.dsl.module

114

115

val userModule = module {

116

single { UserService() }

117

}

118

119

val dataModule = module {

120

single { DatabaseClient() }

121

}

122

123

// Configure application

124

val app = KoinApplication.init()

125

.modules(userModule, dataModule)

126

.properties(mapOf("db.url" to "localhost:5432"))

127

.allowOverride(true)

128

.printLogger(Level.DEBUG)

129

.createEagerInstances()

130

131

// Access the Koin container

132

val koin = app.koin

133

134

// Close when done

135

app.close()

136

```

137

138

139

## Type Definitions

140

141

```kotlin { .api }

142

/**

143

* Type alias for application configuration DSL blocks

144

*/

145

typealias KoinAppDeclaration = KoinApplication.() -> Unit

146

147

148

/**

149

* Logger interface for custom logging implementations

150

*/

151

interface Logger {

152

fun debug(msg: String)

153

fun info(msg: String)

154

fun error(msg: String)

155

}

156

157

/**

158

* Log levels for print logger

159

*/

160

enum class Level {

161

DEBUG, INFO, ERROR, NONE

162

}

163

```