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

Solve PageFactory dependency injection issue #128

Open
aik099 opened this issue Mar 31, 2015 · 0 comments
Open

Solve PageFactory dependency injection issue #128

aik099 opened this issue Mar 31, 2015 · 0 comments

Comments

@aik099
Copy link
Member

aik099 commented Mar 31, 2015

Currently it works like so:

  • the PageFactory class has mandatory $session parameter and optional $config parameter
  • there 4 setter methods for setting AnnotationManager, UrlFactory, Normalizer, DefaultPageLocator
  • in Add page matcher #124 there would one more setter method and dependency added

Then in constructor we create default classes because in majority of cases they won't be replaced.

We need to find a solution, that would:

  • allow user to override any dependency only when he/she needs it
  • prevent BC break (new mandatory constructor argument = bc break), when new dependency is added
  • avoid requiring developer from setting dependencies in specific order (in Add page matcher #124 the MatcherRegistry depends on Session+AnnotationManager, which is also what PageFactory needs)
  • don't force user to write lots of boilerplate code to create PageFactory (that most likely will happen with Builder pattern usage)
  • avoid using DIC because that would make new dependency for the library itself, which can conflict with other dependencies of a project that will use the library

Some crazy implementation idea: since all PageFactory dependencies are objects we can:

  1. take all constructor arguments via func_get_args()
  2. determine which one is which by their class
  3. set dependency to PageFactory
  4. set missing dependencies to defaults
  5. remove setter methods that currently allow to replace dependencies in the middle of PageFactory usage which results in some stale objects (e.g. session) sitting in objects that were created by PageFactory
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

1 participant