Coder Social home page Coder Social logo

暴露的服务注入为空 about arouter HOT 4 CLOSED

alibaba avatar alibaba commented on May 2, 2024
暴露的服务注入为空

from arouter.

Comments (4)

zhi1ong avatar zhi1ong commented on May 2, 2024

服务要由ARouter来实例化和初始化,Application这种不适合用作服务

子模块要拿到Application有太多办法,用ARouter的话,服务的init方法中的参数Context就是Application

from arouter.

SuOtk avatar SuOtk commented on May 2, 2024

我发现我common模块没有依赖app模块的时候,通过Arouter是获取不到app模块中的服务的.
我是想不通过模块间直接依赖的方式,而是通过Arouter获取服务来解决common和app之间依赖关系混乱的问题.
如果common不依赖app,能否通过Arouter获取到app中的服务?

from arouter.

SuOtk avatar SuOtk commented on May 2, 2024

我找到了为什么一直注解的是null.
我在BaseActivity中需要注入一个服务,
但是编译后apt只生成了一个叫做BaseActivity$$ARouter$$Autowired的类.
其他的Activity继承了BaseActivity后,调用了BaseActivity中的ARouter.getInstance().inject(this);
最后执行到AutowiredServiceImpl的autowire方法的时候,这个方法中className是子Activity的类名.找不到对应的Activity$$ARouter$$Autowired,所以没有注入.
为何自动生成的类没有子Activity的Autowired,还是说autowire方法查找的类名不对?

from arouter.

zhi1ong avatar zhi1ong commented on May 2, 2024
  1. 跨模块调用的话,需要抽象出一个接口包,来约束api
  2. 基类中不能使用自动注入,基类中的服务直接采用依赖查找即可

from arouter.

Related Issues (20)

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.