-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Correct me if I'm wrong... I don't think this is supported but this snippet in your docs implies that it is.
final builder = IocContainerBuilder()
..add((container) => DatabaseConnection('my-connection-string'))
..add<UserRepository>(
(container) => UserRepository(container<DatabaseConnection>()),
dispose: (userRepository) => userRepository.dispose(),
)Based on the dispose extension, only scoped singletons are disposed. Therefore the dispose function in the above example will never be called.
ioc_container/lib/ioc_container.dart
Lines 221 to 234 in 313e32d
| Future<void> dispose() async { | |
| assert(isScoped, 'Only dispose scoped containers'); | |
| for (final type in singletons.keys) { | |
| //Note: we don't need to check if the service is a singleton because | |
| //singleton service definitions never have dispose | |
| final serviceDefinition = serviceDefinitionsByType[type]!; | |
| //We can't do a null check here because if a Dart issue | |
| serviceDefinition._dispose.call(singletons[type]); | |
| await serviceDefinition._disposeAsync(singletons[type]); | |
| } | |
| singletons.clear(); | |
| } |
MelbourneDeveloper
Metadata
Metadata
Assignees
Labels
No labels