我在我的项目中使用了包 http,因此,我将客户端的实例(来自包 http)作为依赖项,它是一个抽象类。那么,我应该如何使用正确的注释进行注释呢?在injectable 的文档中,有关于如何注册第三方依赖以及如何注册抽象类的信息。但是如何注册第三方抽象类呢?
这是我的代码
class TokenValueRemoteDataSourceImpl implements TokenValueRemoteDataSource {
TokenValueRemoteDataSourceImpl(this.client);
final http.Client client;
@override
Future<TokenValueModel> getAuthToken({
required EmailAddress emailAddress,
required Password password,
}) async {
final emailAddressString = emailAddress.getOrCrash();
final passwordString = password.getOrCrash();
const stringUrl = 'http://127.0.0.1:8000/api/user/token/';
final response = await client.post(
Uri.parse(stringUrl),
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(
{
'email': emailAddressString,
'password': passwordString,
},
),
);
if (response.statusCode == 200) {
return TokenValueModel.fromJson(
json.decode(response.body) as Map<String, dynamic>,
);
} else {
throw ServerException();
}
}
}
我应该如何为第三方抽象类编写注册模块?
我确实在injectable的文档上看到了这个
@module
abstract class RegisterModule {
@singleton
ThirdPartyType get thirdPartyType;
@prod
@Injectable(as: ThirdPartyAbstract)
ThirdPartyImpl get thirdPartyType;
}
但我不明白在我的代码中应该用什么替换 ThirdPartyImpl 。