Ninjector - the cure for Field Injection Anxiety
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



Ninjector is the cure for a disease called Field Injection Anxiety, widely diagnosed amongst software developers that care about their code. The disease is caused by injection frameworks all too easily allowing dependency injection into a class' fields which seems to be a convenient thing to do in the first place but will inevitably bite you in the back later on. For a more detailed analysis of symptoms and consequences, see this blog post

What does it do?

class Application { … }

 * This class will fail the ApplicationContext to bootstrap
 * due to the injection annotation used on a field.
class ApplicationComponent {

  @Autowired MyCollaborator collaborator;

@DisableFieldInjection registers a tiny Spring extension that will pre-process the bean instances about to be created, scan their fields for common injection annotations (e.g. @Inject, @Autowired, @Resource) and reject the bean instantiation right away.