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

New scope: WeakSingleton #49

Closed
jasperblues opened this issue Aug 10, 2013 · 8 comments
Closed

New scope: WeakSingleton #49

jasperblues opened this issue Aug 10, 2013 · 8 comments
Milestone

Comments

@jasperblues
Copy link
Member

This scope will:

  • Create a new instance if available
  • Allocate it to a pool
  • When no classes are using it, drain it from the pool.
@rhgills
Copy link
Contributor

rhgills commented Sep 11, 2013

Interesting. This seems like it would just boil down to singleton scope in the case where you are instantiating the entire object graph from a single root object - because, at the time of instantiation, there will always be a class using it.

Are you thinking of using this alongside providers?

@jasperblues
Copy link
Member Author

No, I'm talking about Typhoon having an option to hold weak references to singletons. . . Let's say you have a helper component that's used in some view controllers (but not all). . . On mobile you want this to go away when you're not using it.

@rhgills
Copy link
Contributor

rhgills commented Sep 12, 2013

Ahh, right. But to construct the view controller I assume you use a provider, or directly ask the block component factory?

@jasperblues
Copy link
Member Author

Directly asking the factory. . . and weak singleton would make it works as I expect, so I could avoid having to make a provider.

@rhgills
Copy link
Contributor

rhgills commented Sep 18, 2013

Gotcha! The pedantic part of me wants to be as decoupled from the DI container as possible, so I'd probably go for the provider. :)

It would be nice if narrow providers could be automatically generated somehow. Off the top of my head, I think Guice does this.

@jasperblues
Copy link
Member Author

Do you have a code-snippet of what that looks like?

@jasperblues
Copy link
Member Author

Closing . . . I put a typo in the title, and its not updating. . . re-opening as a new issue.

@rhgills
Copy link
Contributor

rhgills commented Oct 3, 2013

Not sure which issue is the new issue, but to answer your question, without using objective c++ and templates, we'd need to autogenerate some code like:

  • (id)newWidget
    {
    return [_factory widget];
    }

along with a setter implementation of the setAssembly: method in < TyphoonInjectionAware >.

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

No branches or pull requests

2 participants