-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
PoC: Isolate dependency injections by specific pattern #59
base: main
Are you sure you want to change the base?
PoC: Isolate dependency injections by specific pattern #59
Conversation
end | ||
|
||
# @api public | ||
def [](*dependency_names) | ||
raise unless match_by_pattern?(dependency_names) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, it will be better to raise some fixed error, not RuntimeError
. I think, it would be great for programmers. WDYT about it?
Here is an overview of what got changed by this pull request: Issues
======
- Added 4
See the complete overview on Codacy |
describe "allow" do | ||
before do | ||
module Test | ||
AutoInject = Dry::AutoInject({one: 1, two: 2}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Redundant curly braces around a hash parameter.
@@ -0,0 +1,34 @@ | |||
# frozen_string_literal: true | |||
|
|||
RSpec.describe "allow condition" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# frozen_string_literal: true | ||
|
||
RSpec.describe "allow condition" do | ||
describe "allow" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe "allow" do | ||
before do | ||
module Test | ||
AutoInject = Dry::AutoInject({one: 1, two: 2}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Space inside } missing.
Hey, I have a idea how to improve injector for scopes in business logic.
I create simple PR for discussing and share this idea
Idea
Imagine a situation when you have an application with 2 different scopes:
Accounts
andOrders
. And in each scope (or domain) you have specific operations and repositories. And in account repo we have a similar method namefind
:We put all these classes into a container and now we can fail if someone injects account repo from
Accounts
toOrders
scope:Important thing
This code (with injection
'accounts.repositories.accounts'
) raise error only after booting and first real call.For detecting these situations I introduce
allow
method with simple regexp pattern:And now, if we will try to inject
'accounts.repositories.accounts'
toOrders::Operations::Create
we fail on creating an instance of operation.Implementation
It's just a proposal of my vision. I'm not sure that
allow
better name for this. But I'll be happy to discuss it with everyone ❤️