Skip to content

Commit

Permalink
Merge pull request #327 from inversify/feat/update-next-getting-start…
Browse files Browse the repository at this point in the history
…ed-docs-page

Update next getting started docs page
  • Loading branch information
notaphplover authored Jan 19, 2025
2 parents 4a13efe + f661358 commit 9244023
Show file tree
Hide file tree
Showing 36 changed files with 212 additions and 53 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
8 changes: 4 additions & 4 deletions packages/docs/tools/inversify-code-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Inversify docs code examples.
## Adding code examples

1. Just create your code example in the `src/examples` folder with an integration test to verify the expected behavior.
2. Use a `// Begin-example` comment to set the begining of the example.
3. Use a `// Exclude-from-example` comment to exclude a sentence from the example.
4. Use a `// End-example` comment to set the end of the example.

- Use a `// Begin-example` comment to set the begining of the example.
- Use a `// Exclude-from-example` comment to exclude a sentence from the example.
- Use a `// Is-inversify-import-example` comment to normalize inversify imports.
- Use a `// End-example` comment to set the end of the example.
2. Run the `build` script.
3. Your code example will be available in the `generated/examples` folder.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, injectable, ResolutionContext } from 'inversify7';

const container: Container = new Container();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, inject } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import {
Container,
Factory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
// Is-inversify-import-example
import { Container, injectable, ResolutionContext } from 'inversify7';

// Begin-example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container } from 'inversify7';

interface CardCatalogProvider<TCard> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import {
BindingMetadata,
Container,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, injectable } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, injectable } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, injectable } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, injectable } from 'inversify7';

@injectable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, injectable } from 'inversify7';

// Begin-example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, injectable } from 'inversify7';

// Begin-example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
// Is-inversify-import-example
import { Container, ResolutionContext } from 'inversify7';

// Begin-example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container } from 'inversify7';

void (async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// Is-inversify-import-example
import {
Container,
ContainerModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, inject, injectable } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, inject, injectable } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, injectable, multiInject } from 'inversify7';

export interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, inject, injectable, named } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, inject, injectable, optional } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
// Is-inversify-import-example
import { Container, postConstruct } from 'inversify7';

// Begin-example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, preDestroy } from 'inversify7';

void (async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, inject, injectable, tagged } from 'inversify7';

interface Weapon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container, injectable, unmanaged } from 'inversify7';

@injectable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Is-inversify-import-example
import { Container } from 'inversify7';

interface Weapon {
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 };
Loading

0 comments on commit 9244023

Please sign in to comment.