@@ -58,19 +58,51 @@ import { ... } from 'https://deno.land/x/lambda_ioc@[VERSION]/lambda-ioc/deno/in
5858## Example
5959
6060``` ts
61- import { createContainer } from ' @coderspirit/lambda-ioc'
61+ import {
62+ constructor ,
63+ createContainer ,
64+ func
65+ } from ' @coderspirit/lambda-ioc'
6266
6367function printNameAndAge(name : string , age : number ) {
6468 console .log (` ${name } is aged ${age } ` )
6569}
70+
71+ class Person {
72+ constructor (
73+ public readonly age : number ,
74+ public readonly name : string
75+ ) {}
76+ }
6677
6778const container = createContainer ()
6879 .registerValue (' someAge' , 5 )
6980 .registerValue (' someName' , ' Timmy' )
81+ // We can register functions
7082 .register (' fn' , func (printNameAndAge , ' someName' , ' someAge' ))
83+ // And constructors too
84+ .register (' Person' , constructor (Person , ' someAge' , ' someName' ))
7185
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' )
7587print () // 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"
7692```
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