HuolalaTech / hll-wp-therouter-android

A framework for assisting in the renovation of Android componentization(帮助 App 进行组件化改造的动态路由框架)
https://therouter.cn/
Apache License 2.0
1.1k stars 129 forks source link

一个接口对应多个 @ServiceProvider 如何能选择用哪个? #105

Closed DylanCaiCoding closed 1 year ago

DylanCaiCoding commented 1 year ago

如果用 ARouter,一个接口有多个实现类, 可以用 path 去决定使用哪个。

@Route(path = "/test/helloworld")
public class HelloWorldServiceImpl implements HelloService {

    @Override
    public String sayHello() {
        return "hello, world!";
    }

    @Override
    public void init(Context context) {
    }
}

@Route(path = "/test/helloandroid")
public class HelloAndroidServiceImpl implements HelloService {

    @Override
    public String sayHello() {
        return "hello, android!";
    }

    @Override
    public void init(Context context) {
    }
}
helloService1 = (HelloService) ARouter.getInstance().build("/test/helloworld").navigation();
helloService2 = (HelloService) ARouter.getInstance().build("/test/helloandroid").navigation();

那么用 TheRouter 该如何实现该需求?看文档没有相关的示例。

kymjs commented 1 year ago

请查看 【1.3 服务提供方】章节的内容:
https://therouter.cn/docs/2022/08/27/01