-
Notifications
You must be signed in to change notification settings - Fork 65
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
Pass custom arguments to a constructor on $injector->execute() #162
Comments
$injector->defineParam($name, $value);
Where are the args coming from, that you need to define them per controller? Or is this just in a HTTP router scenario? |
Yep. Router. Args are args from a route. They go to a controller method as well as to a controller itself to provide the user a controller method (let's say Of course, all this can be designed in a different way. For example, through a separate class Despite this, we yet unable to fully control all constructor arguments when object is created during Regarding the router scenario: if you can advice something about the right way to do this, I will be grateful. How would you do this (and do in your projects)? Thanks! |
In that case, this is what most people do, for what I understand to be your requirements:
I'm fond of making a more specific type to represent a bag of variables, like variable map, as that makes it easier to unit test controllers. |
Well, after that these parameters will be available everywhere, not only for this object and this object's method. In each class which will be instantiated via injector further. This is why I find it useful to have an additional argument in |
I'm going to close this issue on the grounds that:
|
Hello!
In
execute()
method we can pass parameters to a callable, but cannot pass parameters to a class constructor.Example:
How is it possible to get Auryn inject non-class arguments into a class constructor? Real life example: I have many controllers; I would like to use arguments injection in constructor as well as in methods. I do not want to call
define()
for each controller in the app. Sure in theory I can parse the'Foo::someMethod'
string myself and instantiate the controller object, but parsing is already nice done inside Auryn (execute()
andbuildExecutable()
), I do not want to duplicate this functionality. Maybe there is some beautiful method to achieve this?If not, does it make sense to apply
args
inexecute()
to a constructor too, not only to a method call?The text was updated successfully, but these errors were encountered: