Skip to content

Commit

Permalink
docs(README): integrate Token into example code
Browse files Browse the repository at this point in the history
Integrate the usage of tokens into the example code
in the README.
  • Loading branch information
freshgum-bubbles committed May 9, 2024
1 parent 2abda63 commit 886b9b5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ After that, you should be good to go. Read the [documentation][docs-site] to get
## Quick Example

```ts
import { Service, Container } from '@freshgum/typedi';
import { Service, Container, Token } from '@freshgum/typedi';

// Make a service that logs a message to the console.
@Service([])
type LogFunction = (...args: any[]) => void;
const LOG_FUNCTION = new Token<LogFunction>();

@Service([LOG_FUNCTION])
class LogService {
constructor (private logFn: LogFunction) { }

log(message: string) {
console.log(message);
this.logFn(message);
}
}

Expand All @@ -58,6 +63,9 @@ class RootService {
}
}

// Set the logging function...
Container.set(LOG_FUNCTION, console.log);

// Now, run our service!
Container.get(RootService).run();
```
Expand Down

0 comments on commit 886b9b5

Please sign in to comment.