@@ -37,6 +37,7 @@ import { ... } from 'https://deno.land/x/lambda_ioc@[VERSION]/lambda-ioc/deno/in
37
37
38
38
``` ts
39
39
import {
40
+ cc2ic , // Stands for "class-constructor to interface-constructor"
40
41
constructor ,
41
42
createContainer ,
42
43
func
@@ -46,7 +47,12 @@ function printNameAndAge(name: string, age: number) {
46
47
console .log (` ${name } is aged ${age } ` )
47
48
}
48
49
49
- class Person {
50
+ interface Human {
51
+ age: number
52
+ name: readonly string
53
+ }
54
+
55
+ class Person implements Human {
50
56
constructor (
51
57
public readonly age : number ,
52
58
public readonly name : string
@@ -60,6 +66,11 @@ const container = createContainer()
60
66
.register (' fn' , func (printNameAndAge , ' someName' , ' someAge' ))
61
67
// And constructors too
62
68
.register (' Person' , constructor (Person , ' someAge' , ' someName' ))
69
+ // We can do that directly, without having import `constructor`:
70
+ .registerConstructor (' AnotherPerson' , Person , ' someAge' , ' someName' )
71
+ // In case we want to register a "concrete" constructor to provide an
72
+ // abstract interface, we'll have to apply a small hack, using `cc2ic`:
73
+ .registerConstructor (' Human' , cc2ic <Human >()(Person ), ' someAge' , ' someName' )
63
74
// We can "define groups" by using `:` as an infix, the group's name will be
64
75
// the first part of the string before `:`.
65
76
// Groups can be used in all "register" methods.
0 commit comments