Skip to content

Commit

Permalink
🔀 Merge pull request #1461 from palle-k/v4/feat/dependency-injection
Browse files Browse the repository at this point in the history
✨ Adds dependency injection system
  • Loading branch information
jankoenig authored Nov 21, 2022
2 parents 7269607 + e876195 commit 60c441b
Show file tree
Hide file tree
Showing 24 changed files with 1,458 additions and 25 deletions.
3 changes: 3 additions & 0 deletions common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export type DeepPartial<T> = PartialDeep<T>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Constructor<T = AnyObject, ARGS extends unknown[] = any[]> = new (...args: ARGS) => T;

// eslint-disable-next-line @typescript-eslint/ban-types
export type Abstract<T> = Function & { prototype: T };

// Construct object from properties of T that extend U.
export type PickWhere<T, U> = Pick<
T,
Expand Down
39 changes: 38 additions & 1 deletion docs/app-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The app configuration in `app.ts` is the place where you can add plugins, compon
The app configuration files in the `src` folder are the main entry point of your Jovo apps. They usually include the following elements:
- [Components](./components.md) can be registered
- [Plugins](./plugins.md) and [Hooks](./hooks.md) can be added to extend the framework functionality
- [Service providers](./service-providers-dependency-injection.md) can be added for dependency injection
- Framework configurations, like logging behavior, can be modified

Here is an example [`app.ts` file](https://github.com/jovotech/jovo-v4-template/blob/master/src/app.ts):
Expand Down Expand Up @@ -125,7 +126,7 @@ app.use(

## Configuration Elements

The configuration object that can be passed to both the constructor and the `configure()` method contains [components](#components), [plugins](#plugins), [logging](#logging), and [routing](#routing).
The configuration object that can be passed to both the constructor and the `configure()` method contains [components](#components), [plugins](#plugins), [providers](#providers), [logging](#logging), and [routing](#routing).

```typescript
{
Expand All @@ -135,6 +136,9 @@ The configuration object that can be passed to both the constructor and the `con
plugins: [
// ...
],
providers: [
// ...
],
logging: {
// ...
},
Expand Down Expand Up @@ -209,6 +213,39 @@ app.plugins.SomePlugin

This can be helpful if you want to add additional configurations to the default plugin config outside `app.ts`. See [staging](#staging) for more information.

### Providers

You can add service providers for [dependency injection](./services-providers-dependency-injection.md) like this:

```typescript
import { OrderService } from './services/OrderService';
// ...

{
// ...

providers: [
OrderService,
// ...
],
}
```

It is also possible to use the `provide` option to specify a token, for which you want to inject a dependency, separately from the injected value or type. [Learn more about the different provider types here](./service-providers-dependency-injection.md#types-of-providers).

```typescript
{
providers: [
{
provide: OrderService,
useClass: MockOrderService,
},
// ...
]
}
```


### Logging

[Logging](./logging.md) is enabled by adding the following to the app config:
Expand Down
Loading

0 comments on commit 60c441b

Please sign in to comment.