Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 23f596d

Browse files
Merge pull request #3083 from micalevisk/patch-1
docs(fundamentals): improve factory provider example code snippet
2 parents 9d9e81c + eb400ac commit 23f596d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

‎content/fundamentals/dependency-injection.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,20 @@ The `useFactory` syntax allows for creating providers **dynamically**. The actua
242242
@@filename()
243243
const connectionProvider = {
244244
provide: 'CONNECTION',
245-
useFactory: (optionsProvider: OptionsProvider, optionalProvider?: string) => {
245+
useFactory: (optionsProvider: MyOptionsProvider, optionalProvider?: string) => {
246246
const options = optionsProvider.get();
247247
return new DatabaseConnection(options);
248248
},
249-
inject: [OptionsProvider, { token: 'SomeOptionalProvider', optional: true }],
250-
// \_____________/ \__________________/
251-
// This provider The provider with this
252-
// is mandatory. token can resolve to `undefined`.
249+
inject: [MyOptionsProvider, { token: 'SomeOptionalProvider', optional: true }],
250+
// \______________/ \__________________/
251+
// This provider The provider with this token
252+
// is mandatory. can resolve to `undefined`.
253253
};
254254

255255
@Module({
256256
providers: [
257257
connectionProvider,
258-
OptionsProvider,
258+
MyOptionsProvider, // class-based provider
259259
// { provide: 'SomeOptionalProvider', useValue: 'anything' },
260260
],
261261
})
@@ -267,16 +267,16 @@ const connectionProvider = {
267267
const options = optionsProvider.get();
268268
return new DatabaseConnection(options);
269269
},
270-
inject: [OptionsProvider, { token: 'SomeOptionalProvider', optional: true }],
271-
// \_____________/ \__________________/
272-
// This provider The provider with this
273-
// is mandatory. token can resolve to `undefined`.
270+
inject: [MyOptionsProvider, { token: 'SomeOptionalProvider', optional: true }],
271+
// \______________/ \__________________/
272+
// This provider The provider with this token
273+
// is mandatory. can resolve to `undefined`.
274274
};
275275

276276
@Module({
277277
providers: [
278278
connectionProvider,
279-
OptionsProvider,
279+
MyOptionsProvider, // class-base provider
280280
// { provide: 'SomeOptionalProvider', useValue: 'anything' },
281281
],
282282
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /