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

Support all auto inject strategies #19

Merged
merged 5 commits into from
Jul 19, 2016

Conversation

timriley
Copy link
Member

Allow Dry::AutoInject options to be passed to Dry::Component::Container#injector. This allows the underlying auto_inject object to be configured as the user requires, while still retaining dry-component's desired behaviour of lazily loading dependencies.

The immediate benefit of this is that a user can now set up an injector with their own custom strategies container. However, it does mean that any options added to dry-auto_inject in the future will automatically be available for dry-component's injector as well.

This requires a breaking behavioural change, though. The Inject constant that we were setting up automatically on Dry::Component::Container subclasses can't be set up in the same way anymore, since there's no way we can infer by that time if the user wants any particular options to be passed. The recommended behaviour, instead, would be to have the user explicitly define their own constant to store their own preferred injector (e.g. MyApp::Inject = MyApp::Container.injector(my_options)). I think this is a reasonable requirement of users, though, and it was actually what we required of them until the last 0.3.0 release of dry-component, anyway.

Sound OK?

timriley added 3 commits July 10, 2016 17:27
This makes it possible to provide the underlying injector with a custom strategies container (and any other config that may be made available in the future).

This requires some underlying changes, however: the `Inject` constant on `Container` subclasses is no longer set up automatically, since we can’t infer whether the user will want to pass their own options to the injector. Instead, the recommend practice should be that the user creates their own constant to store their preferred injector.
def kwargs
strategies[:kwargs]
def respond_to_missing?(name, _include_private = false)
injector.respond_to?(name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing || super here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've realised that this should actually just be #respond_to? inside a BasicObject subclass (since it doesn't actually offer #respond_to? by default). Will push up this adjustment shortly.

timriley added 2 commits July 12, 2016 11:39
This is because we’re inheriting from BasicObject, which doesn’t provide a respond_to? implementation.
@timriley
Copy link
Member Author

I'll merge this in now since all the code tweaking is done and there was no issue raised with the API adjustment :)

@timriley timriley merged commit abdb70a into master Jul 19, 2016
@timriley timriley deleted the support-all-auto_inject-strategies branch July 19, 2016 07:11
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

Successfully merging this pull request may close these issues.

2 participants