Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add resolve method to load scoped classes #2682

Merged
merged 3 commits into from
Aug 26, 2019

Conversation

kamilmysliwiec
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

resolve() method that allows loading both transient and request-scoped providers dynamically

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@coveralls
Copy link

Pull Request Test Coverage Report for Build 3911

  • 3 of 4 (75.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 95.213%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/core/injector/module.ts 2 3 66.67%
Totals Coverage Status
Change from base Build 3905: -0.02%
Covered Lines: 3640
Relevant Lines: 3823

💛 - Coveralls

Copy link
Contributor

@underfin underfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let trace the issues #2049.Maybe should resolve scope provider.

@Module({
  imports: [],
  providers: [
    {
      scope: Scope.TRANSIENT,
      provide: 'TRANSIENT_PROVIDER',
      useFactory: () => {
        // Does not get called
        console.log('Called `TRANSIENT_PROVIDER`');
        return 'TRANSIENT_PROVIDER_VALUE';
      }
    },
  ]
})
export class AppModule {}

async function bootstrap() {
  const app = await NestFactory.createApplicationContext(AppModule);

  // Returns `null`
  app.get('TRANSIENT_PROVIDER')}
}

I meet error when test with this.

@kamilmysliwiec
Copy link
Member Author

@underfin you should use await app.resolve() instead of .get() method

@kamilmysliwiec kamilmysliwiec added this to the 6.6.0 milestone Aug 24, 2019
@kamilmysliwiec kamilmysliwiec changed the base branch from master to 6.6.0 August 24, 2019 17:45
@kamilmysliwiec kamilmysliwiec merged commit ef264f1 into 6.6.0 Aug 26, 2019
@delete-merged-branch delete-merged-branch bot deleted the feat/resolve-scoped-classes branch August 26, 2019 10:38
@ulrichb
Copy link
Contributor

ulrichb commented Aug 28, 2019

@kamilmysliwiec Is it possible to use this in tests to fake Request-scoped providers?

I would like to resolve services which depend on faked Request-scoped providers.

@kamilmysliwiec
Copy link
Member Author

kamilmysliwiec commented Aug 29, 2019

Yes @ulrichb. I'm working on the docs for this now

@ulrichb
Copy link
Contributor

ulrichb commented Aug 29, 2019

Okay, cool! Looking forward to this.

@aevartg
Copy link

aevartg commented Oct 22, 2019

@kamilmysliwiec, @ulrichb are the docs ready for this? cant seem to find them.

@xxluke
Copy link

xxluke commented Oct 22, 2019

@aevartg I think the docs for this will be written in nestjs/docs.nestjs.com#623

@lock
Copy link

lock bot commented Jan 24, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants