@@ -58,19 +58,51 @@ import { ... } from 'https://deno.land/x/lambda_ioc@[VERSION]/lambda-ioc/deno/in
58
58
## Example
59
59
60
60
``` ts
61
- import { createContainer } from ' @coderspirit/lambda-ioc'
61
+ import {
62
+ constructor ,
63
+ createContainer ,
64
+ func
65
+ } from ' @coderspirit/lambda-ioc'
62
66
63
67
function printNameAndAge(name : string , age : number ) {
64
68
console .log (` ${name } is aged ${age } ` )
65
69
}
70
+
71
+ class Person {
72
+ constructor (
73
+ public readonly age : number ,
74
+ public readonly name : string
75
+ ) {}
76
+ }
66
77
67
78
const container = createContainer ()
68
79
.registerValue (' someAge' , 5 )
69
80
.registerValue (' someName' , ' Timmy' )
81
+ // We can register functions
70
82
.register (' fn' , func (printNameAndAge , ' someName' , ' someAge' ))
83
+ // And constructors too
84
+ .register (' Person' , constructor (Person , ' someAge' , ' someName' ))
71
85
72
- // For now it's always async, we'll improve its API to decide when to expose
73
- // the registered dependencies synchronously or asynchronoyusly in a smart way.
74
- const print = await container .resolve (' fn' )
86
+ const print = container .resolve (' fn' )
75
87
print () // Prints "Timmy is aged 5"
88
+
89
+ const person = container .resolve (' Person' )
90
+ console .print (person .age ) // Prints "5"
91
+ console .print (person .name ) // Prints "Timmy"
76
92
```
93
+
94
+ It is also possible to register and resolve asynchronous factories and
95
+ dependencies. They are not documented yet because some "helpers" are missing,
96
+ and therefore it's a bit more annoying to take advantage of that feature.
97
+
98
+ If you are curious, just try out:
99
+ - ` registerAsync `
100
+ - ` resolveAsync `
101
+
102
+ ## Differences respect to Diddly
103
+
104
+ - First-class support for Deno.
105
+ - First-class support for asynchronous dependency resolution.
106
+ - The container interface has been split into ` ReaderContainer ` and
107
+ ` WriterContainer ` , making it easier to use precise types.
108
+ - More extense documentation.
0 commit comments