Skip to content

Commit

Permalink
Feature/update doc di (#2)
Browse files Browse the repository at this point in the history
* update doc intro to controller

* update doc controller to cli

* update di feature

* add how to read the doc
  • Loading branch information
rsaz committed May 19, 2023
1 parent 782cf79 commit aef30e1
Show file tree
Hide file tree
Showing 28 changed files with 1,400 additions and 893 deletions.
6 changes: 3 additions & 3 deletions docs/cli/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 2

# Generate

In order to provide a better developer experience, the Expresso TS CLI provides a set of commands to help you to **scaffold** the application resources such as use cases, controllers, dto's, providers and services.
In order to provide a better developer experience, the ExpressoTS CLI provides a set of commands to help you to scaffold the application resources such as use cases, controllers, dto's, providers and services.

This command allows developers to stay ahead of the curve by generating the boilerplate code for the application, so they can focus on the business logic.

Expand Down Expand Up @@ -53,10 +53,10 @@ What determine where the resources will be created is the `expressots.config.ts`
:::

:::info
All usecases, controllers and dtos are being created inside of the `useCases` folder. This is not set on the stone, it might change in the soon future.
All usecases, controllers and dtos are being created inside of the `useCases` folder. This is not set on the stone, it might change in the future.
:::

## Expresso TS Config File
## ExpressoTS config file

The configuration file is located in the root folder of the project and it's called `expressots.config.ts`. This file is used to configure the CLI and the project.

Expand Down
8 changes: 4 additions & 4 deletions docs/cli/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 1

# Overview

The Expresso TS CLI is a command-line interface tool that helps you to **create** `ExpressoTS` projects and **scaffold** the application resources such as use cases, controllers, dto's, providers and services.
The ExpressoTS CLI is a command-line interface tool that helps you to `create` ExpressoTS projects and `scaffold` the application resources such as use cases, controllers, dto's, providers and services.

:::info
We use in this tutorial the `npm` package manager, but you can use your favorite package manager such as `yarn` or `pnpm`.
Expand Down Expand Up @@ -40,17 +40,17 @@ Verify the CLI version:
expressots --version
```

## Create an Expresso TS Project
## Create a project

There are two options to create a new project, interactively or silently (passing the options as arguments)

### New project interactively
### Interactively

```bash
expressots new <project-name>
```

### New project silently
### Silently

```bash
expressots new <project-name> -p <package-manager> -t <template>
Expand Down
18 changes: 18 additions & 0 deletions docs/overview/hello.md → docs/hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ Thank you again for being part of this journey with us, Happy Coding! 🚀

---

## How to read the doc

- **[links](intro.md)**: All bold texts are links to other pages of the documentation or external links.
- `code`: helps emphasize code snippets and commands, or key technical terms.
- Alerts: are used to highlight important information.
:::note Used to express general information
:::
:::tip This is a tip
:::
:::info Extra information that is not vital
:::
:::caution Used to indicate spoilers
:::
:::warning Used to indicate when something could go wrong
:::

---

## Support the project

Expresso TS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider:
Expand Down
78 changes: 0 additions & 78 deletions docs/intro.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/overview/_category_.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"position": 2,
"link": {
"type": "generated-index",
"description": "Expresso TS Framework Overview."
"description": "ExpressoTS Framework Overview."
}
}
59 changes: 44 additions & 15 deletions docs/overview/app-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,70 @@ sidebar_position: 3

# App Container

The Expresso TS uses **[InversifyJS](https://inversify.io/)** as its ioC (Inversion of Control) container as it is a powerful tool for managing dependency injection. It is a type-aware container that can be used to manage the instantiation and resolution of objects, as well as the management of their life cycles.
The ExpressoTS uses **[InversifyJS](https://inversify.io/)** as its ioC (Inversion of Control) container. It is a powerful tool for managing dependency injection. It is a type-aware container that can be used to manage the instantiation and resolution of objects, as well as the management of their life cycles.

The container provides a central location for managing dependencies and creating objects that depend on other objects. When a class is registered with the container, its dependencies are automatically resolved and injected into its constructor when it is instantiated. This allows for the creation of complex object graphs with minimal boilerplate code.
The container provides a central location for managing dependencies and creating objects that depend on other objects. When a class is registered with the container, it becomes immediately available for injection into other classes. This allows for the creation of complex object graphs with minimal boilerplate code.

Taking advantage of InversifyJS we created a wrapper to reduce complexity on how controllers, use cases, providers get injected within the application container. The wrapper is called `AppContainer` and it is responsible for registering all the application modules within the container.

Here is an example of how to register **[modules](./module.md)** within the container:
## Creating the container

Upon creating the application container it is possible to define the default scope of the container. The default scope is `RequestScope` which means that all the dependencies will be created once per request. This is the common scope for most web applications used in other frameworks such as Spring Boot or .NET Core as well.

Here is an example on how to create a container:

```typescript
// Create a new container
const appContainer = new AppContainer();

const container = appContainer.create([
// Register all the modules
UserModule,
PaymentModule,
ProductModule
]);
```

export default container;
## Defining the container scope

As mentioned above, if the `defaultScope` is not provided, the default is set to RequestScope. However, it is possible to change the default scope by passing the `defaultScope` as a second argument to the module injection. The BindingScopeEnum is an enum that contains the following values:

- `BindingScopeEnum.Singleton` - The dependency will be created once and will be shared across all requests.
- `BindingScopeEnum.Request` - The dependency will be created once per request.
- `BindingScopeEnum.Transient` - The dependency will be created every time it is requested.

```typescript
const appContainer = new AppContainer();

const container = appContainer.create(
[
// Add your modules here
],
BindingScopeEnum.Singleton,
);
```

:::tip
If you don't pass the `defaultScope` as a second argument, the default scope is set to `RequestScope`.
:::

## Registering modules

The `AppContainer` class has a `create` method that receives an array of modules and returns the container with all the modules registered. The container here created is the same container that is used by the `Application` class to initialize the server.

:::note
InversifyJS contains a helper function called `buildProviderModule()` that can be used to create a module that automatically registers all providers and controllers in a given directory.
Once the container is created developers can register **[modules](./module.md)** within the container:

The function takes a string argument that represents the path to the directory containing the provider and controller classes, and returns a module that can be registered with the InversifyJS container. The module will automatically register all provider and controller classes in the directory and its subdirectories.
```typescript
// Create a new container
const appContainer = new AppContainer();

This is a useful feature when building large applications with many providers and controllers, as it allows you to easily register them all without having to manually register each one.
const container = appContainer.create([
// Register all the modules
UserModule,
PaymentModule,
ProductModule
]);

Note that buildProviderModule() only works with providers and controllers that are decorated with the @injectable() decorator.
:::
export default container;
```

The reason why we created the `AppContainer` class is to reduce the complexity of how the container is created and to provide a way to register modules without too much extra configuration.
The reason why we created the `AppContainer` class is to reduce the complexity of how the container is constructed using Inversify directly, also was to provide a way to register modules without too much extra configuration.

---

Expand Down
Loading

0 comments on commit aef30e1

Please sign in to comment.