# setParent method

1. @override

void setParent(

1. ApplicationContext parent

)
override

Sets the parent of this application context.

Establishes a parent-child relationship where this context becomes the child and inherits configuration and pods from the parent.

### Parent-Child Semantics:

- Configuration Inheritance: Child inherits parent's environment setup
- Pod Delegation: Child can access pods from parent context
- Lifecycle Independence: Child lifecycle independent from parent
- Event Isolation: Events not propagated between parent and child

### Usage:

    // Create parent context with shared services
    final parentContext = GenericApplicationContext();
    parentContext.registerSingleton('dataSource', DataSource());
    parentContext.registerSingleton('configService', ConfigService());
    await parentContext.refresh();

    // Create child context with module-specific services
    final childContext = GenericApplicationContext();
    childContext.setParent(parentContext);
    childContext.registerSingleton('userService', UserService());
    await childContext.refresh();

    // Child can access both its own and parent's pods
    final userService = childContext.getPod<UserService>(); // From child
    final dataSource = childContext.getPod<DataSource>();   // From parent

### Important:

Parent must be set before context refresh and cannot be changed afterward.

## Implementation

    @override
    void setParent(ApplicationContext parent) {
      _parent = parent;
      if (_parent != null) {
        final parentEnvironment = parent.getEnvironment();
        if (_environment == null) {
          setEnvironment(parentEnvironment);
        }
      }
    }