forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/property-injection' into feature/dynamic-create
- Loading branch information
Showing
103 changed files
with
476 additions
and
406 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
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
20 changes: 20 additions & 0 deletions
20
integration/injector/e2e/circular-property-injection.spec.ts
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,20 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { expect } from 'chai'; | ||
import { CircularPropertiesModule } from '../src/circular-properties/circular-properties.module'; | ||
import { CircularService } from '../src/circular-properties/circular.service'; | ||
import { InputPropertiesModule } from '../src/circular-properties/input-properties.module'; | ||
import { InputService } from '../src/circular-properties/input.service'; | ||
|
||
describe('Circular properties dependency (modules)', () => { | ||
it('should resolve circular dependency between providers', async () => { | ||
const builder = Test.createTestingModule({ | ||
imports: [CircularPropertiesModule, InputPropertiesModule], | ||
}); | ||
const testingModule = await builder.compile(); | ||
const inputService = testingModule.get<InputService>(InputService); | ||
const circularService = testingModule.get<CircularService>(CircularService); | ||
|
||
expect(inputService.service).to.be.eql(circularService); | ||
expect(circularService.service).to.be.eql(inputService); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
integration/injector/e2e/circular-structure-dynamic-modules.spec.ts
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,16 @@ | ||
import { expect } from 'chai'; | ||
import { Test } from '@nestjs/testing'; | ||
import { CircularModule } from '../src/circular-structure-dynamic-module/circular.module'; | ||
import { InputService } from '../src/circular-structure-dynamic-module/input.service'; | ||
|
||
describe('Circular structure for dynamic modules', () => { | ||
it('should resolve circular structure with dynamic modules', async () => { | ||
const builder = Test.createTestingModule({ | ||
imports: [CircularModule.forRoot()], | ||
}); | ||
const testingModule = await builder.compile(); | ||
const inputService = testingModule.get<InputService>(InputService); | ||
|
||
expect(inputService).to.be.instanceof(InputService); | ||
}); | ||
}); |
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,16 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { expect } from 'chai'; | ||
import { DefaultsModule } from '../src/defaults/defaults.module'; | ||
import { DefaultsService } from '../src/defaults/defaults.service'; | ||
|
||
describe('Injector', () => { | ||
describe('when optional', () => { | ||
it(`should make use of default assignments`, async () => { | ||
const builder = Test.createTestingModule({ | ||
imports: [DefaultsModule], | ||
}); | ||
const app = await builder.compile(); | ||
expect(app.get(DefaultsService).coreService.default).to.be.true; | ||
}); | ||
}); | ||
}); |
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,18 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { expect } from 'chai'; | ||
import { DependencyService } from '../src/properties/dependency.service'; | ||
import { PropertiesModule } from '../src/properties/properties.module'; | ||
import { PropertiesService } from '../src/properties/properties.service'; | ||
|
||
describe('Injector', () => { | ||
it('should resolve property-based dependencies', async () => { | ||
const builder = Test.createTestingModule({ | ||
imports: [PropertiesModule], | ||
}); | ||
const app = await builder.compile(); | ||
const dependency = app.get(DependencyService); | ||
|
||
expect(app.get(PropertiesService).service).to.be.eql(dependency); | ||
expect(app.get(PropertiesService).token).to.be.true; | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
integration/injector/src/circular-properties/circular-properties.module.ts
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,10 @@ | ||
import { forwardRef, Module } from '@nestjs/common'; | ||
import { CircularService } from './circular.service'; | ||
import { InputPropertiesModule } from './input-properties.module'; | ||
|
||
@Module({ | ||
imports: [forwardRef(() => InputPropertiesModule)], | ||
providers: [CircularService], | ||
exports: [CircularService], | ||
}) | ||
export class CircularPropertiesModule {} |
8 changes: 8 additions & 0 deletions
8
integration/injector/src/circular-properties/circular.service.ts
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,8 @@ | ||
import { forwardRef, Inject, Injectable } from '@nestjs/common'; | ||
import { InputService } from './input.service'; | ||
|
||
@Injectable() | ||
export class CircularService { | ||
@Inject(forwardRef(() => InputService)) | ||
public readonly service: InputService; | ||
} |
10 changes: 10 additions & 0 deletions
10
integration/injector/src/circular-properties/input-properties.module.ts
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,10 @@ | ||
import { forwardRef, Module } from '@nestjs/common'; | ||
import { CircularPropertiesModule } from './circular-properties.module'; | ||
import { InputService } from './input.service'; | ||
|
||
@Module({ | ||
imports: [forwardRef(() => CircularPropertiesModule)], | ||
providers: [InputService], | ||
exports: [InputService], | ||
}) | ||
export class InputPropertiesModule {} |
8 changes: 8 additions & 0 deletions
8
integration/injector/src/circular-properties/input.service.ts
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,8 @@ | ||
import { forwardRef, Inject, Injectable } from '@nestjs/common'; | ||
import { CircularService } from './circular.service'; | ||
|
||
@Injectable() | ||
export class InputService { | ||
@Inject(forwardRef(() => CircularService)) | ||
public readonly service: CircularService; | ||
} |
16 changes: 16 additions & 0 deletions
16
integration/injector/src/circular-structure-dynamic-module/circular.module.ts
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,16 @@ | ||
import { DynamicModule } from '@nestjs/common'; | ||
import { InputService } from './input.service'; | ||
|
||
export class CircularModule { | ||
static forRoot(): DynamicModule { | ||
const a = { | ||
module: CircularModule, | ||
providers: [ | ||
InputService, | ||
], | ||
b: null, | ||
}; | ||
a.b = a; | ||
return a; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
integration/injector/src/circular-structure-dynamic-module/input.service.ts
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,5 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class InputService { | ||
} |
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,4 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class CoreService {} |
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,7 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { DefaultsService } from './defaults.service'; | ||
|
||
@Module({ | ||
providers: [DefaultsService], | ||
}) | ||
export class DefaultsModule {} |
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,11 @@ | ||
import { Inject, Injectable, Optional } from '@nestjs/common'; | ||
import { CoreService } from './core.service'; | ||
|
||
@Injectable() | ||
export class DefaultsService { | ||
constructor( | ||
@Inject(CoreService) | ||
@Optional() | ||
public readonly coreService = { default: true }, | ||
) {} | ||
} |
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,4 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class DependencyService {} |
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,15 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { DependencyService } from './dependency.service'; | ||
import { PropertiesService } from './properties.service'; | ||
|
||
@Module({ | ||
providers: [ | ||
DependencyService, | ||
PropertiesService, | ||
{ | ||
provide: 'token', | ||
useValue: true, | ||
}, | ||
], | ||
}) | ||
export class PropertiesModule {} |
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,8 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { DependencyService } from './dependency.service'; | ||
|
||
@Injectable() | ||
export class PropertiesService { | ||
@Inject() service: DependencyService; | ||
@Inject('token') token: boolean; | ||
} |
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 |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
"packages": [ | ||
"bundle/*" | ||
], | ||
"version": "5.3.10" | ||
"version": "5.3.11" | ||
} |
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
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
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
Oops, something went wrong.