0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Abstracted Nest "Provider" registration from boot

This allows us to make underlying changes to how it works
This commit is contained in:
Fabien "egg" O'Carroll 2023-12-12 16:33:31 +07:00
parent e285ddcafa
commit cca1978b2f
2 changed files with 10 additions and 1 deletions

View file

@ -393,7 +393,7 @@ async function initServices({config}) {
async function initNestDependencies() {
debug('Begin: initNestDependencies');
const GhostNestApp = require('@tryghost/ghost');
const providers = GhostNestApp.AppModule.providers;
const providers = [];
const urlUtils = require('./shared/url-utils');
providers.push({
provide: 'models',
@ -436,6 +436,9 @@ async function initNestDependencies() {
provide: 'settings',
useValue: require('./shared/settings-cache')
});
for (const provider of providers) {
GhostNestApp.addProvider(provider);
}
debug('End: initNestDependencies');
}

View file

@ -2,6 +2,7 @@ import 'reflect-metadata';
import {AppModule} from './nestjs/app.module';
import {NestApplication, NestFactory} from '@nestjs/core';
import {registerEvents} from './common/decorators/handle-event.decorator';
import {ClassProvider, ValueProvider} from '@nestjs/common';
export async function create() {
const app = await NestFactory.create(AppModule);
@ -10,6 +11,11 @@ export async function create() {
return app;
}
export function addProvider(obj: ClassProvider | ValueProvider) {
AppModule.providers?.push(obj);
AppModule.exports?.push(obj.provide);
}
export {
AppModule
};