Sunday, November 18, 2012

Bookmark and Share

Watching a talk from Square's CTO Bob Lee, I just learned about Dagger, a new dependency injection framework for Java and Android which is currently in the works at Square, Inc.

Considering the number of existing DI solutions in the Java space – e.g. CDI, Google Guice and Spring – one might wonder whether the world really needs yet another DI framework. According to Bob's talk, Dagger (a pun on "directed acyclic graph") is the attempt to create a modern and fast DI framework based on the insights gained during development and usage of Guice (Bob was the founder of the Guice project at Google). And indeed does Dagger come up with some quite interesting ideas which I'd like to discuss in more detail in the following.


Dagger is centered around the annotations for dependency injection defined by JSR 330 (which Bob Lee co-led). This is a good thing because it increases portability of your code between different DI solutions.

Dependencies are retrieved by annotating fields or constructors with @Inject:

public class Circus {

    private final Artist artist;

    public Circus(Artist artist) {
        this.artist = artist;


To satisfy dependencies, Dagger creates the required objects using their @Inject-annotated constructor (in turn creating and passing any dependencies) or the default no-args constructor.

Where that's not possible (e.g. when an implementation of an interface needs to be injected) provider methods can be used. Provider methods must be annotated with @Provides and be defined in a class annotated with @Module like this:

public class CircusModule {
    @Provides Artist provideArtist() {
        return new Juggler();

The @Module annotation is also used to define the entry point of an application:

@Module( entryPoints=CircusApp.class )
public class CircusModule {

This entry point represents the root of the object graph managed by Dagger. As we'll see in a moment, explicitly defining the root allows for compile-time validation of the dependency graph. An instance of the entry point type can be retrieved from the ObjectGraph class, passing the module(s) to create the graph from:

ObjectGraph objectGraph = ObjectGraph.create(new CircusModule());
CircusApp circus = objectGraph.get(CircusApp.class);

Dagger also also provides support for qualifiers, lazy injection, injection of providers and more. The project's web site gives a good overview. Apart from that it's interesting to see what Dagger deliberately does not support to avoid an increased complexity:

  • Circular dependencies between objects
  • Method injection
  • Custom scopes (Objects are either newly created for each injection or singleton-scoped)

Code generation

DI frameworks usually make intensive use of reflection to examine annotations, find injection points, create managed objects etc. While reflection today isn't as expensive as it used to be in earlier years, it still can take a considerable amount of time to create large object graphs with lots of dependencies.

Dagger tries to improve upon that with the help of code generation. It provides a JSR 269 based annotation processor which is used at compile time to create an adapter class for each managed type. These adapter classes contain all the logic required at run time to set up the object graph by invoking constructors and populating references to other objects, without making use of reflection.

This approach promises performance benefits over reflection-based ways for creating object graphs typically used by DI frameworks. On my machine Dagger needed roughly half the time to initialize the graph of the CoffeeApp example using the generated classes compared to using reflection (which it also supports as fallback). Of course this is by no means a comprehensive benchmark and can't be compared with other frameworks but it surely shows the potential of the code generation approach.

The annotation processor also performs a validation of the object graph and its dependencies at compile time. So if for instance no matching type (or more than one) can be found for a given injection point, the build will fail with an error message describing the problem. This helps in reducing turn-around times compared to discovering this sort of error only at application start-up. Implementing this sort of checks using an annotation processor makes them available in IDEs (which typically can integrate annotation processors) as well as headless builds, e.g. on a CI server.

Object graph visualization

Not mentioned in the documentation, Dagger also provides an annotation processor which generates a GraphViz file visualizing the object graph. This may be useful to get an understanding of unknown object graphs. The following shows the graph from the CoffeeApp example:


Dagger is a new dependency injection framework for Java and Android.

While it's still in the works (the current version is 0.9 and there are still some apparent bugs), I find the concept of using an annotation processor for validating the object graph at compile time and generating code for a faster initialization at runtime very interesting. In particular on mobile devices fast start up times are essential for a good user experience.

I also like the idea of leaving out features which might provide some value but would add much complexity. One thing I'm missing though is some sort of interceptor or decorator mechanism. This would be helpful for implementing typical cross-cutting concerns.

It'll definitely be interesting to see how the code generation approach works out in practice and whether other DI solutions possibly adapt that idea.


Gopi Krishna said...

Dependency Injection is a software design pattern in which components are given their dependencies instead of hard coding them within the component. This relieves a component from locating the dependency and makes dependencies configurable. This helps in making components reusable, maintainable and testable.

AngularJS provides a supreme Dependency Injection mechanism. Know More: AngularJS Training in Chennai

Priya Kannan said...

This information really worth saying, i think you are master of the content and thank you so much sharing that valuable information and get new skills after refer that post.
PEGA Training in Chennai

Freddie King said...

Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point. | |

Durante said...

Thanks for posting...

Rangga Alexandra said...

Manfaat Daun Kemuning Untuk Menurunkan Berat Badantips bagi penderita jantung bengkak

Harish said...

Thank you for sharing this useful information.

Angularjs course in Chennai | Angularjs Training in Chennai

simbu said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
java training in omr

java training in annanagar | java training in chennai

java training in marathahalli | java training in btm layout

java training in rajaji nagar | java training in jayanagar

amilu B said...

I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
python training in chennai | python training in bangalore

python online training | python training in pune

python training in chennai | python training in bangalore

python training in tambaram |

pooja saravanan said...

This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 

Hadoop Training in Chennai

Hadoop Training in Bangalore

Big data training in tambaram

Big data training in Sholinganallur

Big data training in annanagar

Big data training in Velachery

Ram priya said...

Fantastic work! This is the type of information that should follow collective approximately the web. Embarrassment captivating position Google for not positioning this transmit higher! Enlarge taking place greater than and visit my web situate
Data Science Training in Chennai
Data science training in bangalore
Data science online training
Data science training in pune
Data science training in kalyan nagar
selenium training in chennai

digi mark said...

Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision. 

rpa training in Chennai

rpa training in pune

rpa online training

rpa training in bangalore

rpa training in Chennai

rpa training in Chennai

rpa training in velachery

rpa training in tambaram

saran latha said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
Devops Training in Chennai

Devops Training in Bangalore

amala said...

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

rpa training in Chennai | rpa training in pune

rpa training in tambaram | rpa training in sholinganallur

rpa training in Chennai | rpa training in velachery

rpa online training | rpa training in bangalore

sai said...

Really great post, I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries.
python training in tambaram
python training in annanagar
python training in OMR

sudhagar raja said...

Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
java training in omr | oracle training in chennai

java training in annanagar | java training in chennai

sai said...

I was looking for this certain information for a long time. Thank you and good luck.
python online training
python training in OMR
python training in tambaram
python training in annanagar

Revathy A said...

All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.

angularjs Training in chennai
angularjs Training in chennai

angularjs-Training in tambaram

angularjs-Training in sholinganallur

angularjs-Training in velachery

Sri Nithya said...

Excellent and useful blog admin, I would like to read more about this topic.
Angularjs Training in Chennai
Angularjs Training Institute in Chennai
Angularjs Training center in Chennai
Angularjs Training Chennai

Ram priya said...

This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
Data science course in tambaram | Data Science course in anna nagar
Data Science course in chennai | Data science course in Bangalore
Data Science course in marathahalli | Data Science course in btm

Sri Nithya said...

Thanks for sharing this information admin, it helps me to learn new things. Continue sharing more like this.
DevOps certification Chennai
DevOps Training in Chennai
DevOps Training institutes in Chennai
RPA Training in Chennai
Blue Prism Training in Chennai
UiPath Training in Chennai

sumathi s said...

I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
industrial safety course in chennai

Unknown said...

We are DevOps Training in Bangalore,Chennai, Pune using Class Room. myTectra offers Live Online DevOps Training Globally

Pankaj Singh said...

Nice Blog, Thank you so much sharing with us. Visit for
Web Designing Company in Delhi

chitra pragya said...

Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…

angularjs online Training

angularjs Training in marathahalli

angularjs interview questions and answers

angularjs Training in bangalore

angularjs Training in bangalore

Ananya Krishnan said...

Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.

Good to learn about DevOps at this time.

devops training in chennai | devops training in chennai with placement | devops training in chennai omr | devops training in velachery | devops training in chennai tambaram | devops institutes in chennai

Unknown said...

your post is the very organized way and easily understandable. Doing a good job. Thank you for sharing this content.
rpa training in chennai | rpa training in velachery | rpa training in chennai omr

Unknown said...

myTectra a global learning solutions company helps transform people and organization to gain real, lasting benefits.Join Today.Ready to Unlock your Learning Potential !Read More...

Aman CSE said...

Thanks for such a wonderful blog. The blog is full of information on Blueprism. The best part of the blog is that the information shared is from basics and everyone is capable of understandig with the help of this blog on Blueprism. Keep sharing your valuable information and helps others who is searching for knowledge on Blueprism .
Thanks and Regards,
Blueprism training cost in chennai

Anjali Siva said...

Thanks for taking time to share these java concepts. It is really helpful.
Angularjs Training institute in Chennai
Angular 2 Training in Chennai
Angular 4 Training in Chennai
RPA Training in Chennai
DevOps Training in Chennai
Blue Prism Training in Chennai

kim john said...

I have to thank for sharing this blog, it gives lots of information to me.
Python Training in Chennai
Python course in Chennai
Python Classes in Chennai
Python Training Chennai
Python Training in Velachery
Python course in Tambaram

Unknown said...

best hiv doctor in delhi

sachin.ogeninfo said...

fridge repair in gurgaon

sachin.ogeninfo said...

English Song lyrics

Unknown said...

HIV Specialist Doctors

Sakthi Murugan said...

Thanks for sharing a valuable information to us. your article inspired me more. I Would like to get more updates in future.
Selenium Training in Chennai
selenium testing training in chennai
iOS Training in Chennai
Digital Marketing Training in Chennai
hadoop big data training in chennai
best institute for big data in chennai
Hadoop Training in adyar

Anbarasan14 said...

One of the best blogs that I have read till now. Thanks for your contribution in sharing such a useful information.

French Institute in Chennai
French Language Course in Chennai
French Training in Chennai
French Coaching near me
German Training in Chennai
German Classes in Chennai
German Language Course in Chennai

sultana mohammed said...

I am really enjoying reading your well written articles.
It looks like you spend a lot of effort and time on your blog.
I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..
Best Java Training Center in Bangalore
Best Java Coaching Centers in Bangalore
Java Coaching Classes in Bangalore
big data coaching in bangalore
hadoop certification courses in bangalore
hadoop training centers in bangalore

Aruna ram said...

This post is marvelous!!! I read this blog very great content and i learn more details. Thank you so much.
Big Data Hadoop Training institutes in Bangalore
Big Data Hadoop Training institute in Bangalore
Best Big Data Hadoop Training in Bangalore
Big Data Hadoop Training in Chennai Velachery
Big Data Hadoop Training in Tnagar
Big Data Hadoop Course in Nungambakkam
Big Data Hadoop Course in karappakkam
Big Data Hadoop Training in padur
Big Data Hadoop Training in Chennai

LindaJasmine said...

Very informative post. Looking for this information for a long time. Thanks for Sharing.

Tableau Training in Chennai
Tableau Course in Chennai
Tableau Certification in Chennai
Tableau Training Institutes in Chennai
Tableau Certification
Tableau Training
Tableau Course

Shadeep shree said...

Really great blog… Thanks for your useful information.
Best Spoken English Institute in Coimbatore
Spoken English Course in Coimbatore
Best Spoken English Coaching Center in Coimbatore
Coimbatore Spoken English Center
English Speaking Course in Coimbatore

Eminent It Info said...

I have read your blog its very attractive and impressive. I like it your blog.
Python training in marathahalli | Best Python training in bangalore | Best Python institute in marathahalli bangalore

Anonymous said...

Selenium is one of the most popular automated testing tool used to automate various types of applications. Selenium is a package of several testing tools designed in a way for to support and encourage automation testing of functional aspects of web-based applications and a wide range of browsers and platforms and for the same reason, it is referred to as a Suite.

Selenium Interview Questions and Answers
Javascript Interview Questions
Human Resource (HR) Interview Questions

Shiva Shakthi said...

The blog which you have shared is more informative. Thanks for your information.
JAVA Training Center in Coimbatore
JAVA Training
JAVA Certification Course
JAVA Certification Training
JAVA Training Courses

nanadhini chandran said...

feeling so good to read your information's in the blog.
thanks for sharing your ideas with us and add more info.
Python Training in Guindy
Python Training in Saidapet
python programming in bangalore
python programming classes in bangalore

aruna ram said...

Hi, Your blog is very impress to me. I am very glad to read your post. Thank you for your sharing.
PHP Classes in Bangalore
PHP Training Center in Bangalore
PHP Course in Adyar
PHP Course in Perambur
PHP Training in Chennai Velachery
PHP Training in Tnagar
PHP Course in Sholinganallur
PHP Training in Navalur

Sathish K said...

Thank you for sharing this wonderful information on your blog.

IoT courses in Chennai
Internet of Things Training in Chennai
Internet of Things Course
IoT courses in Velachery
IoT courses in Tambaram
IoT courses in Adyar

Vicky Ram said...

Excellent post! keep sharing such a post

Guest posting sites

Hemapriya said...

The information which you have shared is more informative to us. Thanks for your blog.
ccna course in coimbatore
ccna training in coimbatore
ccna course in coimbatore with placement
best ccna training institute in coimbatore
ccna certification in coimbatore

Vicky Ram said...

Thanks for your sharing such a useful information. this was really helpful to me.

Article submission sites
Guest posting sites

amsa leka said...

Thanks for such a great article here. I was searching for something like this for quite a long time and at last, I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays. Well written article.Thank You for Sharing with Us angular 7 training in velachery

Dwarakesh babu said...

When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.

AWS Interview Questions And Answers

AWS Training in Chennai | Best AWS Training in Chennai

AWS Training in Pune | Best Amazon Web Services Training in Pune

Sadhana Rathore said...

Thanks for sharing this coding admin, really helpful.
ReactJS Training in Chennai
ReactJS Training
ReactJS Training in Adyar
AWS Training in Chennai
Angular 6 Training in Chennai
Angular 5 Training in Chennai

LindaJasmine said...

Awesome Writing. Your way of expressing things is very interesting. I have become a fan of your writing. Pls keep on writing.

SAS Training in Chennai
SAS Course in Chennai
SAS Training Institutes in Chennai
SAS Institute in Chennai
SAS Training Chennai
SAS Training Institute in Chennai
SAS Courses in Chennai
SAS Training Center in Chennai

pavithra dass said...

This post is much helpful for us. This is really very massive value to all the readers and it will be the only reason for the post to get popular with great authority.
Java J2ee Training in Chennai
German Training Institute in Chennai
german language coaching centres in chennai
Java Coaching Center in Chennai
Best Java Training in Chennai
German Training Centers in Chennai

Ananya Krishnan said...

Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.

Good to learn about DevOps at this time.

devops training in chennai | devops training in chennai with placement | devops training in chennai omr | devops training in velachery | devops training in chennai tambaram | devops institutes in chennai | devops certification in chennai | trending technologies list 2018

mercyroy said...

Amazing blog you have given and you made a great work.surely i would look into this insight and i hope it will help me to clear my points.please share more information's.
Android Training in Sholinganallur
Android Courses in T nagar
Android Course in Anna Nagar
best android training center in bangalore

mercyroy said...

Thanks for the great post on your blog, it really gives me an insight on this topic.I must thank you for this informative ideas. I hope you will post again soon.
android app development training in bangalore
Android Training in Mogappair
Android Training in Nungambakkam
Android Training in Karapakkam

Anand said...

Nice Stuff!!!
Java Training in Chennai
Python Training in Chennai
IOT Training in Chennai
Selenium Training in Chennai
Data Science Training in Chennai
FSD Training in Chennai
MEAN Stack Training in Chennai

venu bharath said...

The post was amazing. You are an excellent writer. Your choice of words is extra-ordinary.. Thanks for Posting.
Informatica institutes in Chennai
Informatica courses in Chennai
Informatica Training in Velachery
Informatica Training in Tambaram
Informatica Training in Adyar

LindaJasmine said...

Awesome Post. The content showcases your in-depth knowledge. Pls keep on writing.
IELTS coaching in Chennai
IELTS Training in Chennai
IELTS coaching centre in Chennai
Best IELTS coaching in Chennai
IELTS classes in Chennai
Best IELTS coaching centres in Chennai
IELTS Centre in Chennai
IELTS Training
IELTS Course in Chennai

Praylin S said...

Well written content with great information. I really liked your article. Keep posting. Regards.
C C++ Training in Chennai | C Training in Chennai | C++ Training in Chennai | C++ Training | C Language Training | C++ Programming Course | C and C++ Institute | C C++ Training in Chennai | C Language Training in Chennai

LindaJasmine said...

Amazing Blog. The liked your way of writing. It is easy to understand. Waiting for your next post.
Node JS Training in Chennai
Node JS Course in Chennai
Node JS Advanced Training
Node JS Training Institute in chennai
Node JS Training Institutes in chennai
Node JS Course
Informatica Training in Chennai
Informatica Training center Chennai
Informatica Training Institute in Chennai

Nadeem Malik said...

hello sir,
thanks for giving that type of information. digital marketing company in delhi

Vikash Kumar said...

visa immigration service in delhi

Aman CSE said...

Such a wonderful article on AWS. I think its the best information on AWS on internet today. Its always helpful when you are searching information on such an important topic like AWS and you found such a wonderful article on AWS with full information.Requesting you to keep posting such a wonderful article on other topics too.
Thanks and regards,
AWS training in chennai
aws course in chennai what is the qualification
aws authorized training partner in chennai
aws certification exam centers in chennai
aws course fees details
aws training in Omr



you can search low-cost website with high-quality website functions.
Today Join Us
Call: +91 - 8076909847

website designing company delhi

best interior designers in delhi

website designing company

seo services delhi

Best It Service Provider:

1. Website Designing And Development.
2. SEO Services.
3. Software Development.
4. Mobile App Development.

sachin.ogeninfo said...

cattle feed bags supplier

MuleSoft Training said...

Really this is great information for every Java beginners. I appreciate your work. keep sharing..


Riya Raj said...

The blog which you are shared is helpful for us. Thanks for your information.
Software testing Institute in Coimbatore
Best Software Testing Institute in Coimbatore
Best Software Testing Training Institutes
Software Testing Course
Software Testing Training

dhivya said...

In the beginning, I would like to thank you much about this great post. Its very useful and helpful for anyone looking for tips. I like your writing style and I hope you will keep doing this good working.
Angularjs Training in Bangalore
Angularjs Training Institute In Bangalore
Angularjs Training Institute in Bangalore
Angularjs Classes in Bangalore

Aadhya Sharma said...

It’s really nice blog and nice information is given in this is very useful for me.Thanks for sharing!
Web Development Company in Noida

asha said...

Nice Post
devops course in bangalore

best devops training in bangalore

Devops certification training in bangalore

devops training in bangalore

devops training institute in bangalore

mounika said...

Nice post..

salesforce training in btm

salesforce admin training in btm

salesforce developer training in btm

Praylin S said...

Great post! Thanks for sharing.
IoT Training in Chennai | IoT Courses in Chennai | IoT Courses | IoT Training | IoT Certification | Internet of Things Training in Chennai | Internet of Things Training | Internet of Things Course

mounika said...

Nice post..
robotics courses in BTM

robotic process automation training in BTM

blue prism training in BTM

rpa training in BTM

automation anywhere training in BTM

Vikash Kumar said...

Epoxy Grout manufacturer in delhi

uma said...

this is a great information... keep sharing

digital marketing courses in Bangalore With placement

digital marketing training in Bangalore

seo training in Bangalore

chandana said...

Thanks for sharing the valuable information.
data science training in Marathahalli

best data science courses in Marathahalli

data science institute in Marathahalli

data science certification Marathahalli

data analytics training in Marathahalli

data science training institute in Marathahalli

Akash Thakur said...

Laminated Doors manufacturer in hubli
Thanks for giving great kind of information. So useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing the knowledge.

aruna ram said...

Great idea! Thank you for your wonderful post and very easily understand to me. Really good work please keeping...
Web Designing Training in Bangalore
Web Development Courses in Bangalore
Web Designing Course in Tnagar
Web Designing Training in Saidapet
Web Designing Course in Omr
Web Designing Training in Omr

High Technologies Solutions said...

Thanks for sharing this valuable information about Python with us, it is really helpful article!