Skip to content
This repository was archived by the owner on Apr 21, 2024. It is now read-only.

Commit b391283

Browse files
committed
docs: replicate README.md file
1 parent d606ace commit b391283

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lambda-ioc/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { ... } from 'https://deno.land/x/lambda_ioc@[VERSION]/lambda-ioc/deno/in
3737

3838
```ts
3939
import {
40+
cc2ic, // Stands for "class-constructor to interface-constructor"
4041
constructor,
4142
createContainer,
4243
func
@@ -46,7 +47,12 @@ function printNameAndAge(name: string, age: number) {
4647
console.log(`${name} is aged ${age}`)
4748
}
4849

49-
class Person {
50+
interface Human {
51+
age: number
52+
name: readonly string
53+
}
54+
55+
class Person implements Human {
5056
constructor(
5157
public readonly age: number,
5258
public readonly name: string
@@ -60,6 +66,11 @@ const container = createContainer()
6066
.register('fn', func(printNameAndAge, 'someName', 'someAge'))
6167
// And constructors too
6268
.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')
6374
// We can "define groups" by using `:` as an infix, the group's name will be
6475
// the first part of the string before `:`.
6576
// Groups can be used in all "register" methods.

0 commit comments

Comments
 (0)