Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Oosting committed Jan 4, 2024
1 parent 8f3d255 commit e5c64f1
Show file tree
Hide file tree
Showing 24 changed files with 291 additions and 79 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ import type { BundleInterface } from '@wildsea/dependency-injection'
/* Define the bundle configuration class */
export class MyBundleConfig {
debug: boolean;
graphics: Partial<GraphicsConfig>;
myService: Partial<MyServiceConfig>;
}

/* Create the bundle definition */
export class MyBundle implements BundleInterface<MyBundleConfig> {

constructor(
public timer: Timer,
public graphics: GraphicsManager,
public api: ApiManager,
public service: MyService,
) {}

/* The configure() method wires the services in this bundle */
Expand All @@ -215,12 +215,15 @@ export class MyBundle implements BundleInterface<MyBundleConfig> {
/* Apply configuration overrides */
const config = {...new MyBundleConfig(), ...overrides};

/* Register the services in this bundle */
container.transient(Timer, []);
container.singleton(GraphicsManager, [Timer, config.graphics]);
/* Get some global parameters (could also be passed via config, based on the scope) */
const apiKey = container.getParameter('apiKey');

/* Wire the services in this bundle */
container.transient(ApiManager, [apiKey]);
container.singleton(MyService, [ApiManager, config.myService]);

/* Then register the bundle itself */
container.register(MyBundle, [Timer, GraphicsManager]);
container.register(MyBundle, [Timer, MyService]);
}
}
```
Expand Down Expand Up @@ -254,14 +257,14 @@ container.addExtension(MyBundle, {
```ts
import { MyBundle } from "."

/* You must call `build` first. This will wire the services. */
/* You must call `build` first. */
container.build();

const ext = container.getExtension(MyBundle);

if (ext) {
const bundleTimer = ext.timer; /* instanceof 'Timer' */
const bundleGraphics = ext.graphics; /* instanceof 'GraphicsManager' */
const instance1 = ext.api; /* instanceof 'ApiManager' */
const instance2 = ext.service; /* instanceof 'MyService' */
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e5c64f1

Please sign in to comment.