-
Notifications
You must be signed in to change notification settings - Fork 3
01. Introduction
Jim Riordan edited this page Aug 10, 2016
·
1 revision
Yadic (Yet another dependency injection container) is a super small and lightning fast dependency injection (DI) container. If you aren't familiar with the concept of DI, please read Martin Fowler's article and the wikipedia page. While other DI containers we've been working with evolve towards big monolithic frameworks, Yadic tries to follow the Linux philosophy: do one thing, do it well.
Yadic is build upon several basic principles:
- Constructor injection and static factory method injection only. No support for field injection. Objects should be created in one go using either a constructor or a static factory method. It shouldn't be possible to create an object in an invalid state with partially injected collaborators.
- Objects are wired together by a class/interface name. No String keys.
- Dependency injection should be done in code, not in XML, not in annotations. XML is not refactoring friendly. Annotations add library/framework specific code to the classes that shouldn't know anything about this library/framework. Container agnostic apps is a good thing.
- One application can have multiple containers. There's no need to create one global container that contains the whole object graph for your application.
- Object scope/lifetime shouldn't be baked into your DI container. Java already provides object scope in terms of blocks and objects. If you want your objects to live in a different scope, you can create separate containers for each scope e.g. a request scope container and an application scope container in a web application.
- DI container should have a very simple API so you can learn it in minutes without studying several hundred pages long books
- Object wiring should be done in nanoseconds, not in seconds. If you care about fast build times then your container can't spend 2 seconds parsing XML file and building a dependency graph.