@@ -58,17 +58,67 @@ 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 ()
68- .register (' someAge' , value (5 ))
69- .register (' someName' , value (' Timmy' ))
79+ .registerValue (' someAge' , 5 )
80+ .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' ))
85+ // We can "define groups" by using `:` as an infix, the group's name will be
86+ // the first part of the string before `:`.
87+ // Groups can be used in all "register" methods.
88+ .registerValue (' group1:a' , 1 ) // group == 'group1'
89+ .registerValue (' group1:b' , 2 )
90+ .registerValue (' group2:a' , 3 ) // group == 'group2'
91+ .registerValue (' group2:b' , 4 )
7192
93+ // We can resolve registered functions
7294const print = container .resolve (' fn' )
7395print () // Prints "Timmy is aged 5"
96+
97+ // We can resolve registered constructors
98+ const person = container .resolve (' Person' )
99+ console .print (person .age ) // Prints "5"
100+ console .print (person .name ) // Prints "Timmy"
101+
102+ // We can resolve registered "groups"
103+ container .resolveGroup (' group1' ) // ~ [1, 2], not necessarily in the same order
104+ container .resolveGroup (' group2' ) // ~ [3, 4], not necessarily in the same order
74105```
106+
107+ It is also possible to register and resolve asynchronous factories and
108+ dependencies. They are not documented yet because some "helpers" are missing,
109+ and therefore it's a bit more annoying to take advantage of that feature.
110+
111+ If you are curious, just try out:
112+ - ` registerAsync `
113+ - ` resolveAsync `
114+
115+ ## Differences respect to Diddly
116+
117+ - First-class support for Deno.
118+ - First-class support for asynchronous dependency resolution.
119+ - Stricter types for dependencies re-registration.
120+ - Groups registration and resolution: very useful when we need to resolve all
121+ dependencies belonging to a same category.
122+ - The container interface has been split into ` ReaderContainer ` and
123+ ` WriterContainer ` , making it easier to use precise types.
124+ - More extense documentation.
0 commit comments