Closed creynders closed 10 years ago
Obviously this would be a breaking change
Yeah, I can think of at least one enterprise app that would break as a result of this change.
how about a separate method
I think I like the configure
approach. So if I understand correctly, the original API (passing an optional wiring
object) would require that each value in that object is, itself, a named dependency. While the configure
approach would permit each value in the object to be the actual value to be injected?
So if I understand correctly, the original API (passing an optional wiring object) would require that each value in that object is, itself, a named dependency. While the configure approach would permit each value in the object to be the actual value to be injected?
Yes indeed. The more I think about configure
the more I like it, it has some real potential, especially if it accepts functions that return configuration objects as well.
(Caveat: configure
cannot be called on view wirings, for obvious reasons.)
I'm thinking of the following
.configure('myModel', {
foo:"bar"
});
The object is passed to the constructor function of MyModel.
.configure('myModel', function(context){
return {
foo: "bar"
}
});
The result of the function call is passed to the constructor function of MyModel.
If configure
receives an array, either directly or as a result of calling a function, each element will be passed as an argument to the constructor function, i.e.
//MyModel
function MyModel( foo, baz ){
}
//config
.configure( 'myModel', ['bar','qux'] );
Results in foo
having the value 'bar' and baz
'qux'
Some remarks:
configure
method.configure
are relayed to the constructor function, except for key
obviously.Sounds great - Let's do it!
I've found need for being able to pass a configuration object to instances that are created by the resolver.
E.g.:
Here I want the UserModel instance to be injected with a specific url upon instantiation. The above is obviously a solution, but a bit cumbersome. For instance if there are any other config options I'd like to pass, I'll need to wire them as values as well. In this case I use the optional
wiring
parameter all wire* methods have, but TBH I think this has very little use cases and am starting to think it would be better to turn it into an optionaloptions
parameter. So we could do this:Obviously this would be a breaking change. If you don't like this approach how about a separate method, something like: