getConversionService method
Retrieves the currently assigned ConversionService
.
This method provides access to the type conversion infrastructure for manual conversion operations when dependency injection is not available or suitable.
Usage Contexts:
- Configuration property resolution
- Data binding in web controllers
- Custom deserialization logic
- Format parsing and validation
Example:
class ConfigurationParser {
final ConversionService conversionService;
ConfigurationParser(this.conversionService);
T parseConfiguration<T>(String key, String value) {
return conversionService.convert<String, T>(value);
}
}
// Manual usage
final service = context.getConversionService();
final timeout = service.convert<String, int>("30");
final ratio = service.convert<String, double>("0.85");
final enabled = service.convert<String, bool>("true");
final date = service.convert<String, DateTime>("2023-12-25");
print("Parsed values: $timeout, $ratio, $enabled, $date");
Implementation
@override
ConversionService getConversionService() => _conversionService;