register method
Registers the specified persister
as supporting its
persister
.supportedType, and returns persister
as result.
The returning of the input is useful for writing code such as:
final persister = Persistence.get().register(SomePersister());
Throws ConflictingPersisterException if there's already a persister
with the same persister
.signature present, since it would be impossible
to validate the correct reading of files if multiple persisters have
the same signature.
Implementation
Persister register(Persister persister) {
// Check for duplicate singature.
for (var value in _knownPersisters.values) {
if (value.signature.toLowerCase() == persister.signature.toLowerCase()) {
throw ConflictingPersisterException(
'Trying to register persister ${persister.runtimeType} with '
'signature "${persister.signature}", but existing persister '
'${value.runtimeType} already has that signature.');
}
}
_knownPersisters[persister.supportedType] = persister;
return persister;
}