-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
SearchExtension: ignores classes that do not have autowired parameters #316
base: master
Are you sure you want to change the base?
Conversation
…od (BC break)" This reverts commit 87662eb.
added Definition::getDescriptor(), Helpers::entityToString()
This would make it hard to reason about why some service is not registered. |
@JanTvrdik could you show me an example? |
I want only reduce the exclude list, where you don't need to register services. |
The similar condition is \ReflectionClass($class)::isInstantiable(). |
This is an absolutely fatal BC break. |
Could you more explain the BC break to me, because I don't understand. |
Service B depends on service A Why? Services don't even have to come from the same repository so the developer doesn't have control over service A. Service B not being registered instead of reporting that A is missing even though developer configured search extension to find it is really confusing behavior. I am aware of this feature and was digging in Nette internals for 6 years now and I would still be lost if this happened to me. |
@mabar Thank you for explain I tried your example class A
{
public function __construct()
{
}
}
class B
{
public function __construct(private A $a)
{
}
}
Both classes are loaded by search extension and I get exception: A is regstered, B is loaded in config: B is registered, A is loaded: **Nette\DI\ServiceCreationException: These use cases have legit exception. Nothing about missing Garage\B. But in this case is little bit worse I revert A and add scalar parameter class A
{
public function __construct(string $foo)
{
}
} Nette\DI\ServiceCreationException: Service of type Garage\B: Service of type Garage\A required by $a in B::__construct() not found. Did you add it to configuration file? The response on question What do you think? |
…od (BC break)" This reverts commit 87662eb.
added Definition::getDescriptor(), Helpers::entityToString()
@h4kuna I explain why BC break. I have component FrontMenu rendering simple set of links from array not from database and I pass this component into presenter as service. I register this components by search option - *Menu. This service has no autowired dependency - it would be skipped from search and I must register it manually. Similar problem appear when service use instead of autowiring passing dependency by setter. So it is very big BC break. But I understand your wish - to have registering services more simple without boilerplate of many hand services registrations or many hand excluded classes. I hate it too. I use another search system than you - I search only classes by specific class name suffixes like *Model, *Control, *Menu etc. The list becames longer and longer and I loos control over what class is service and what class is not. To make registering classes as services clear again, I have an idea of implement in DI new feature. Aautomatic registration of services by attribut #[Service] - without writing any code in neon files! #[Service] Such a code is absolutely clear, without any doubts, any questions - is this class properly registered or not , or is this class service or is it not service ?? Inventing such attribute would solve much more better your problem and would be NO BC. |
This is not true. If the class has no dependencies, it is registered by default behavior.
No, if you want to use setter, you must define class in neon, in this moment the behavior is same. I want only extends the excluded classes by automatic. It is mean the dependencies are not defined, like scalar parameter or missing object. |
May be I do not understand 100% what you mean. "No, if you want to use setter, you must define class in neon, in this moment the behavior is same." I can define service in search by suffix: search:
Component: class MyControl
} Model class used by component: class MyModel extends AbstractModel Use in presenter: public function __construct( public function actionDoSomething(): void This scenario you must use when you use MyControl in multiple presenters with different models. In this case configuration creates by suffix service without any knowledge about its dependency. I guess that your proposal would exclude MyControl out of services. The other point to consider is, that you can use search to register services without any dependency intentionally. These services would also be skipped. |
@mildabre |
8655bcb
to
59cf699
Compare
Hello,
I use SearchExtension and I have primitive classes in project, but all these classes I must register to
exclude
section. I think if the class does not have autowired parameters it can be skipped.Example:
Simple class
Actual behavior throw exception:
In this moment I must add class to
search -> exclude
.New bahevior
If SearchExtension skip this class and I don't need dependency by another class, everything is ok.
If I need dependency by another class, for example
Garage\Model\Baz
. I get exception:I must manually register the class and I think it is legit. I can't think of a use case where it might be undesirable.
After apply this patch, the result is: