flutter - Flutter Injectable:通过注解注入多个泛型类型实例
问题描述
我在我的颤振项目中使用 get_it 进行依赖注入。现在我正在尝试用可注入的方法来用注释替换我的手写依赖文件。
我有一个特殊情况,我有一个通用的类,必须用不同的 T 值注入 3 次。
class TestBloc<T> {
...
}
这是我的旧配置中的样子:
sl.registerFactory(() => TestBloc<One>(...);
sl.registerFactory(() => TestBloc<Two>(...);
sl.registerFactory(() => TestBloc<Three>(...);
我怎样才能注释类以使其工作?
当我添加@injectable
@injectable
class TestBloc<T> {
...
}
我明白了(当然):
gh.factory<_i34.TestBloc<dynamic>>(() =>_i34.TestBloc<dynamic>(...);
如何注释才能得到这个?
gh.factory<_i34.TestBloc<One>>(() =>_i34.TestBloc<One>(...);
gh.factory<_i34.TestBloc<Two>>(() =>_i34.TestBloc<Two>(...);
gh.factory<_i34.TestBloc<Three>>(() =>_i34.TestBloc<Three>(...);
解决方案
推荐阅读
- mysql - 使用 MySql 的端点测试 Node Express API
- bash - Bash - 以数字格式转换意大利日期
- kubernetes - 如何重新创建 Kubernetes 持久卷?
- swift - DispatchQueue 是否在自己的线程中运行?
- python-3.x - 如何在不同图表之间共享 pyqtgraph 图?
- python - 如何在 Flask 应用程序中启动后台线程?
- python - 将 JSON 文件作为 Post Request Flask 发送
- javascript - 无法访问多维数组的第二个索引
- mongodb - 从 shell 脚本连接中运行 MongoDB shell 命令被拒绝
- ruby-on-rails - 多对多关联如何在 Rails 应用程序中工作?