GithubHelp home page GithubHelp logo

dagger2's Introduction

Dagger2

Dagger2学习笔记 只调用DaggerxxxComponent.create().inject(mContainer)的时候就会初始化被@inject标记的xxx的实例。 如果Module只有有参构造器,则必须显式传入Module实例。 一个Component可以包含多个Module,这样Component获取依赖时候会自动从多个Module中查找获取,Module间不能有重复方法。添加多个Module有两种方法,一种是在Component的注解@Component(modules={××××,×××}) 添加多个modules 另外一种添加多个Module的方法可以被使用Module中的@Module(includes={××××,×××})

Component定义方法的规则

1)对应上面苹果容器的例子,Component的方法输入参数一般只有一个,对应了需要注入的Container。有输入参数返回值类型就是void 2)Component的方法可以没有输入参数,但是就必须有返回值: Step1:返回的实例会先从事先定义的Module中查找,如果找不到跳到Step2 Step2 : 使用该类带@Inject的构造器来生成返回的实例,并同时也会递归注入构造器参数以及带@Inject的成员变量

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.