Skip to content

Commit

Permalink
perf: prefer use factory instead of use value when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Nov 15, 2023
1 parent ef53448 commit 53d2094
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class ConfigurableModuleBuilder<
const providers: Array<Provider> = [
{
provide: self.options.optionsInjectionToken,
useValue: this.omitExtras(options, self.extras),
useFactory: () => this.omitExtras(options, self.extras),
},
];
if (self.options.alwaysTransient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ export class InternalCoreModuleFactory {
return InternalCoreModule.register([
{
provide: ExternalContextCreator,
useValue: ExternalContextCreator.fromContainer(container),
useFactory: () => ExternalContextCreator.fromContainer(container),
},
{
provide: ModulesContainer,
useValue: container.getModules(),
useFactory: () => container.getModules(),
},
{
provide: HttpAdapterHost,
useValue: httpAdapterHost,
useFactory: () => httpAdapterHost,
},
{
provide: LazyModuleLoader,
useFactory: lazyModuleLoaderFactory,
},
{
provide: SerializedGraph,
useValue: container.serializedGraph,
useFactory: () => container.serializedGraph,
},
]);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/router/router-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class RouterModule {
providers: [
{
provide: ROUTES,
useValue: routes,
useFactory: () => routes,
},
],
};
Expand Down
3 changes: 2 additions & 1 deletion packages/microservices/module/clients.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class ClientsModule {
const clientsOptions = !Array.isArray(options) ? options.clients : options;
const clients = (clientsOptions || []).map(item => ({
provide: item.name,
useValue: this.assignOnAppShutdownHook(ClientProxyFactory.create(item)),
useFactory: () =>
this.assignOnAppShutdownHook(ClientProxyFactory.create(item)),
}));
return {
module: ClientsModule,
Expand Down
2 changes: 1 addition & 1 deletion packages/platform-express/multer/multer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class MulterModule {
return {
module: MulterModule,
providers: [
{ provide: MULTER_MODULE_OPTIONS, useValue: options },
{ provide: MULTER_MODULE_OPTIONS, useFactory: () => options },
{
provide: MULTER_MODULE_ID,
useValue: randomStringGenerator(),
Expand Down

0 comments on commit 53d2094

Please sign in to comment.