From 0bae4559605c2b2bbcfa7d0bbaf5d17c99608073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6hls?= Date: Fri, 21 Jan 2022 15:48:35 +0100 Subject: [PATCH] wip --- application.md | 5 ++--- navigation.js | 3 ++- service-providers.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/application.md b/application.md index 5f08d18..c307e2c 100644 --- a/application.md +++ b/application.md @@ -11,10 +11,9 @@ You’ll find bootstrapping files for HTTP and console applications inside of th ## IoC Container -Supercharge’s `Application` class is also an IoC container used to manage class dependencies. This allows apps to follow the concept of dependency injection. Well, dependency injection is a funky term that basically describes “injecting” dependencies into a class. - -Injecting dependencies instead of letting classes resolve them on their own has the benefit of controlling the dependencies instead of relying on existing setups. Controlling dependencies is especially helpful during testing. +Supercharge’s `Application` class is also an [IoC container](/docs/service-container) used to manage class dependencies. This allows apps to follow the concept of dependency injection. +👉 [IoC Container docs](/docs/service-container) ## Start a Web Application The `server.ts` file in your root directory contains the logic to serve a Supercharge web app. It creates a new application and starts the HTTP server. Serving an HTTP server is as simple as invoking the `server.ts` file with Node.js to start a web application: diff --git a/navigation.js b/navigation.js index 8350e51..707c1cf 100644 --- a/navigation.js +++ b/navigation.js @@ -21,7 +21,8 @@ module.exports = { // Development: 'development', Deployment: 'deployment', // Bootstrappers: 'bootstrappers' - 'Service Providers': 'service-providers' + 'Service Container': 'service-container', + 'Service Providers': 'service-providers', } }, diff --git a/service-providers.md b/service-providers.md index 48bedaf..b46b6fd 100644 --- a/service-providers.md +++ b/service-providers.md @@ -1,9 +1,53 @@ # Service Providers +- [Introduction](#introduction) +- [Creating Service Providers](#creating-service-providers) + - [The Register method](#the-register-method) + - [The Boot method](#the-boot-method) +- [Registering Providers](#registering-providers) + + + ## Introduction tba. + +## Creating Service Providers +All service providers should extends the `ServiceProvider` class provided by `@supercharge/support`. The main methods you can implement in your service provider are `register` and `boot`: + ```ts +import { ServiceProvider } from '@supercharge/support' +import { MarkdownRenderer } from './markdown-renderer' + +export class MarkdownServiceProvider extends ServiceProvider { + /** + * Register application services to the container. + */ + override register (): void { + this.app().singleton(MarkdownRenderer, () => { + return new MarkdownRenderer(this.app()) + }) + } + /** + * Boot application services. + */ + override async boot (): Promise { + await this.app().make(MarkdownRenderer).boot() + } +} ``` + + + +### The Register Method +tba. + + +### The Boot Method +tba. + + +## Registering Providers +tba.