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

Improve scoping mechanism #314

Closed
seesharper opened this issue Sep 27, 2016 · 4 comments
Closed

Improve scoping mechanism #314

seesharper opened this issue Sep 27, 2016 · 4 comments

Comments

@seesharper
Copy link
Owner

seesharper commented Sep 27, 2016

The implementation today consists of the following main components

  • Scope - The actual scope
  • ScopeManager - A manager class that manages scopes and keeps track of the current scope.
  • IScopeManagerProvider
    • PerThreadScopeManagerProvider (default)
    • PerLogicalCallContextScopeManagerProvider (async/await)
    • PerWebRequestScopeManagerProvider(LightInject.Web)

So the IScopeManagerProvider is providing scope managers either per thread or per logical call context (AsyncLocal<T>)

In order to support resolving services directly off the scope (#291), we need to be able to set the current scope managed by the scope manager. By creating context specific scope managers (PerThreadScopeManager, PerLogicalCallContextScopeManager) we will not only simplify the current implementation, but we will also lay the foundation for supporting both parallell scopes(#112) and resolving services directly off the scope.

@dadhi
Copy link
Contributor

dadhi commented Sep 27, 2016

Hello,

It is interesting to see how the impl / ideas are developed in sync for similar tools. I've played with idea for container implementing the "scope manager" abstraction to enable "parallel" / container-bound scopes.

@seesharper
Copy link
Owner Author

Absolutely. It is one of the really nice things about open source. We can learn from each other 👍

@seesharper
Copy link
Owner Author

seesharper commented Sep 27, 2016

Basic support for resolving services off the scope.

            var container = CreateContainer();
            container.Register<IFoo, Foo>(new PerScopeLifetime());
            using (var scope = container.BeginScope())
            {
                var instance = scope.GetInstance<IFoo>();
                Assert.IsType<Foo>(instance);
            }

seesharper added a commit that referenced this issue Sep 27, 2016
seesharper added a commit that referenced this issue Sep 28, 2016
@seesharper
Copy link
Owner Author

Implemented all GetInstance convenience methods as extension methods so that we don't need to reimplement all these method on the Scope class

seesharper added a commit that referenced this issue Oct 5, 2016
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

No branches or pull requests

2 participants