Skip to content

Commit

Permalink
feat(inversify-site): update next getting started API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
notaphplover committed Jan 19, 2025
1 parent 430c4bf commit f661358
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ sidebar_position: 1
title: Getting started
---
import CodeBlock from '@theme/CodeBlock';
import gettingStartedSource from '@inversifyjs/code-examples/generated/examples/gettingStarted.ts.txt';
import gettingStartedSource from '@inversifyjs/code-examples/generated/examples/v7/gettingStarted.ts.txt';

# Getting started

Start by installing `inversify` and `reflect-metadata`:

```bash
npm install inversify reflect-metadata
npm install inversify@alpha reflect-metadata
```

Next, initialize your first container and add some bindings:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { describe, expect, it } from '@jest/globals';

import { ninja } from './gettingStarted';

describe('getting started', () => {
it('should provide a ninja with a weapon with right damage', () => {
expect(ninja.katana.damage).toBe(10);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Is-inversify-import-example
import { Container, inject, injectable } from 'inversify7';

@injectable()
class Katana {
public readonly damage: number = 10;
}

@injectable()
class Ninja {
constructor(
@inject(Katana)
public readonly katana: Katana,
) {}
}

const container: Container = new Container();

container.bind(Ninja).toSelf();
container.bind(Katana).toSelf();

const ninja: Ninja = container.get(Ninja);

console.log(ninja.katana.damage); // Prints 10
// End-example

export { ninja };

0 comments on commit f661358

Please sign in to comment.