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: TyphoonScopeNonContained #206

Closed
jasperblues opened this issue Apr 12, 2014 · 3 comments
Closed

New scope: TyphoonScopeNonContained #206

jasperblues opened this issue Apr 12, 2014 · 3 comments

Comments

@jasperblues
Copy link
Member

The final scope to implement will be TyphoonScopeNonContained

  • This will do dependency injection on objects outside the container, by advising/wrapping init methods
  • Optionally will allow specifying which init method(s) get wrapped

This scope provides a way to avoid the _'anemic model anti-pattern'_. Consider the following case:

  • An object is emitted eg CoreData
  • In OO such an object should have properties as well as methods, however in order to provide useful methods, we sometimes need collaborators.
  • Traditionally we're left with a choice to either forgo DI and hard-wire dependency or settle for anemic model objects.

This scope aims to address this problem. It should be used sparingly as there are some drawbacks, the main being:

  • Assumes all instances of a given class are configured with the same dependencies.
@alexgarbarev
Copy link
Contributor

Maybe move 'lazy' property to TyphoonScopeLazySingleton and remove property? I don't like 'NonContained' name because it is not clear (maybe better InitSwizzled or something else)

@jasperblues
Copy link
Member Author

@alexgarvarev I agree. this means a somewhat intimidating menu if scopes to learn. But it eliminates the other concept/duplication entirely. And there's been some confusion there.

@jasperblues
Copy link
Member Author

After debating this with @alexgarbarev we've decided to drop it for now. The drawbacks and added complexity seem to outweigh the merits.

  • Users wishing to have 'rich' model objects can fairly easily instruct Typhoon to inject a given instance with little extra boilerplate. (Some frameworks provide hooks for this). On the other-hand there's some serious drawbacks to the 'global' configuration that some DI containers impose when they use this approach. . . it shouldn't be encouraged in Typhoon.

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