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

Root request scope #1147

Closed
wants to merge 6 commits into from
Closed

Conversation

tonyhallett
Copy link
Contributor

Description

Added a new binding scope - inRootRequestScope()
This works similarly to request scope but applies to all container.get calls that occur during the 'root' container.get. This allows scope to be shared across toDynamicValue

container.bind<Weapon>(TYPE.DynamicWeapon).toDynamicValue((context) => {
    return context.container.get<Weapon>(TYPE.Weapon);
});

This is facilitated by Context.parentContext, which is managed by Container._planAndResolve, and Context.rootRequestScope which is managed by the resolver.

Related Issue

#1143

Motivation and Context

As soon as you use toDynamicValue you cannot resolve a previously resolved value unless it is singleton scoped. With this code change there is now the concept of a root request which can be scoped to.

How Has This Been Tested?

TDD. Test that demonstrates what cannot be achieved with request scope that can now be achieved with root request scope.

Types of changes

  • Updated docs / Refactor code / Added a tests case (non-breaking change)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the changelog.

As always, if you merge these changes I will happily update the documentation.

@tonyhallett tonyhallett marked this pull request as draft April 28, 2021 16:37
@tonyhallett
Copy link
Contributor Author

Parent context should be a stack. I have a better abstraction that uses the ideas in this pull request that will add in a fresh pull request shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants