IgorBabkin / ts-ioc-container

Full feature, lightweight, dependency injection container
17 stars 1 forks source link

what "asScoped()" actually means? #38

Closed keepitsimple closed 2 years ago

keepitsimple commented 2 years ago

There are 3 possible scopes for a Provider":

ResolutionScoped

    The same instance will be resolved for each resolution of this dependency during a single resolution chain

ContainerScoped

    The dependency container will return the same instance each time a resolution for this dependency is requested. This is similar to being a singleton, however if a child container is made, that child container will resolve an instance unique to it.

Could you please clarify?

IgorBabkin commented 2 years ago

This documention is outdated. I will update it later. Scope - is just container inside of another container. And you can define registration of provider for any scope. You can define it by level (0, 1, 2, 3...deeper). Or by assigning tags to scope. And if you make provider asSingleton().perTags('page') then it will be singleton per this whole scope and all nested one

keepitsimple commented 2 years ago

thank you for clarification!