misha / iroh

Simple dependency injection.
Apache License 2.0
6 stars 0 forks source link

Implement @Autowired for constructors. #1

Closed misha closed 10 years ago

misha commented 10 years ago

Common use case for a DI container. Rather than annotating fields, a single constructor would carry the annotation, and all of its arguments would be injected during construction for an @Autowired field of that type. This is an alternative to directly annotating fields that often allows for less type-fu when unit testing, as well as the ability to turn off Iroh altogether and just pass in the correct instances manually.

public class Example {

    @Component
    public static class Dependency { ... }

    @Autowired
    public Example(Dependency a) {
        Assert.assertNotNull(a);
    }

    @Test
    public void testAutowiredConstructor() { ... }
}
misha commented 10 years ago

This issue is tabled until I get a better sense of the direction Iroh should be heading towards (more features vs. simpler features).