# addSingleton method

1. @override

Future<void> addSingleton(

1. String name, {
2. ObjectHolder<Object>? object,
3. ObjectFactory<Object>? factory,

})

Add the given singleton object to the singleton cache of this factory.

This method registers a fully initialized singleton instance and cleans up any intermediate state (factories, early references).

`name`: The name of the pod to register `qualifiedName`: The fully qualified name of the pod to register `singleton`: The fully initialized singleton instance

Example:

    final userService = UserService();
    // Perform dependency injection and initialization
    injectDependencies(userService);
    initializePod(userService);

    registry.addSingleton('userService', userService);

Add the given singleton factory for building the specified singleton if necessary.

This method registers a factory function that can create the singleton instance when needed. Useful for lazy initialization and circular dependency resolution.

`name`: The name of the pod to register a factory for `singletonFactory`: The factory function that creates the singleton instance

Example:

    registry.addSingletonFactory('dataSource', () {
      final dataSource = DataSource();
      dataSource.initialize();
      return dataSource;
    });

## Implementation

    @override
    Future<void> addSingleton(String name, {ObjectHolder<Object>? object, ObjectFactory<Object>? factory}) async {
      super.addSingleton(name, object: object, factory: factory);

      final filter = ((Class cls) => cls != Class<Object>() && cls.isInstance(object?.getValue()));
      _singletonAndNonSingletonPodNames.keys.toList().removeWhere(filter);
      _singletonPodNames.keys.toList().removeWhere(filter);
    }