-
Notifications
You must be signed in to change notification settings - Fork 268
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
Definition inheritance #90
Comments
100% agree with this feature. . . it gives a very good ROI on development effort. |
Implemented initializer inheritance only (no property inheritance) in 65ba872. If a child specifies any initializer block (including an empty one) as opposed to nil, the child's initializer overrides the parents. No inheritance of the parent's class yet, either. |
Nice work so far :) |
Thanks! One thing I don't like is the obscurity of the unit tests. Consider the following test:
The meaning of this test is unclear without looking at the DefinitionInheritanceAssembly code. Just from looking at the test, we don't know if what we're verifying is actually correct. The test itself doesn't tell us if childKnightWithConstructorDependency actually creates a knight. The test also does not tell us that the childKnightWithConstructorDependency definition specifies that a CampaignQuest be injected into the initializer during construction of the Knight. I tried my best to make this clear with names, but I feel it could be improved by constructing a minimal assembly in the tests. If you're familiar with XUnit Test Patterns, the DefinitionInheritanceAssembly is an immutable shared fixture. We should be constructing a minimal fixture in each test. So the test used as an example above could be changed to:
And from this very verbose base, we could extract some test utility methods to abstract away some details.
You still need to drill down to test utility methods to fully understand the test, but it should be clear from their names what they do - and, unlike before, the test is explicitly involved in setting up the assembly. This solves the problem of having a large assembly with many definitions of which only some of which are relevant to the current test. The use of test utility methods to dynamically create assemblies in this way gives us lots of flexibility. I'd love to hear any thoughts on the idea in general and on which method of adding a definition to the assembly you prefer. Namely:
|
Hey Robert, Yes, I agree with this. I think the problem is that there are some (aka a lot) integration tests that should really be unit tests. . . ie we’re building XML or ‘block'-style assemblies, in order to test lower-level functionality. . . I think the integration tests still definitely have value, but a lot of them could be moved down as unit tests. I’m not sure that I understood what you meant by this:
If you’re asking about the different ways to construct a definition the idea was this: The alloc/init style is verbose and for internal use. Is this what you meant? Were you suggesting this could be changed / improved ? |
I just came to the same realization myself that we're testing behavior of the component factory by building assemblies. I agree that we should reduce the amount of integration tests, covering perhaps only a few relevant cases end-to-end, while moving the rest of the tested functionality down to the unit test level. In regards to your question, I was trying to figure out how to register a definition with the component factory and completely overlooking the simplest and best solution: the Since we last spoke, I've:
I'm very curious to hear any thoughts on replacing these integration tests with unit tests and with the XMLBuilder used in AsComponentDefinitionTests. |
This is done, right? |
In a very basic state. There are four tests in TyphoonComponentFactoryTests which cover the behavior implemented right now. The initializer will be inherited from a definitions parent, if none is specified for the child. But, no inheritance occurs for properties (yet). And specifying an initializer on the child will completely override the parents initializer. Improving both of these is on my TODO list. |
What would be the most self-evident behavior here? Perhaps we should follow the Spring behavior? (this is a Spring-ish feature)
Let's leave it open. I think we can call it finished once we can inherit, and optionally override specific properties as well. |
No progress on this since we last spoke. Now that #107 is winding down, this is next up. Sorry for the glacial pace. I'll get this finished up ASAP. |
Hey no worries man! . . . was just checking. . . we're all volunteers here. @mivasi is checking out what's there so far. . . he also needs the new ObjectGraph scope - i'm planning to implement that ASAP. |
Yup, sorry: that sounded a bit terse now that I reread it! My bad! But I do want to get this done ASAP; it'll let me deduplicate a substantial amount of code in one of my own projects. Always good to know that we have some real users wanting the features that are top priority. 👍 |
Haha - it didn't sound terse. . I just didn't want you to feel under pressure. @mivasi actually wrote what I believe was the first open-source DI container for Objective-C. . . it was the first one I came across anyway - back in 2010. . . so its great that he's helping us test out the new features. |
No worries, no pressure here! :) And that is great! Glad to have you here, @mivasi. |
Just tried this and its not working for me. . . . the way I would implement this feature would be to copy all of the attributes from the parent definition(s) to the child during start-up. . . rather than trying to introspect this at runtime. |
What's not working? And thanks, that seems like a better approach, I'll explore that! |
I didn't get time to create a failing test - sorry. . But here's what I tried:
|
Implemented at definition level, instead of in instance builder. |
Spring-style. See http://docs.spring.io/spring/docs/3.2.4.RELEASE/spring-framework-reference/html/beans.html#beans-child-bean-definitions.
Basically: Specify a parent definition.
Block syntax would be something like:
For XML it can be a simple
parent="definitionName"
attribute inside the component element.The text was updated successfully, but these errors were encountered: