generated from expressots/expressots-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { provide } from "inversify-binding-decorators"; | ||
|
||
/** | ||
* Abstract class ApplicationBase. | ||
* | ||
* ApplicationBase serves as the foundational structure for building | ||
* server applications. It declares the lifecycle hooks that allow | ||
* subclasses to configure services, handle post-server initialization, | ||
* and perform cleanup when the server is shutting down. Extending | ||
* classes are required to provide implementations for these methods | ||
* to define specific behaviors for their particular use cases. | ||
* | ||
* @example | ||
* class Application extends ApplicationBase { | ||
* protected configureServices() { //... } | ||
* protected postServerInitialization() { //... } | ||
* protected serverShutdown() { //... } | ||
* } | ||
* | ||
* @export | ||
* @abstract | ||
*/ | ||
@provide(ApplicationBase) | ||
abstract class ApplicationBase { | ||
/** | ||
* Method to configure services that should be initialized | ||
* before the server starts. It must be implemented by the | ||
* extending class to set up necessary services or configurations. | ||
* Can return a Promise for async configuration. | ||
* | ||
* @abstract | ||
* @returns {void | Promise<void>} | ||
*/ | ||
protected abstract configureServices(): void | Promise<void>; | ||
|
||
/** | ||
* Method to configure services or actions that should be executed | ||
* after the server starts. It allows the extending class to perform | ||
* any necessary operations once the server is up and running. | ||
* Can return a Promise for async execution. | ||
* | ||
* @abstract | ||
* @returns {void | Promise<void>} | ||
*/ | ||
protected abstract postServerInitialization(): void | Promise<void>; | ||
|
||
/** | ||
* Method to perform any necessary actions or cleanup after the server | ||
* is shutting down. This might include closing database connections, | ||
* stopping background tasks, or other cleanup activities. It provides | ||
* a clean exit point for the server. | ||
* Can return a Promise for async cleanup. | ||
* | ||
* @abstract | ||
* @returns {void | Promise<void>} | ||
*/ | ||
protected abstract serverShutdown(): void | Promise<void>; | ||
} | ||
|
||
export { ApplicationBase }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters