org.qi4j.api.entity

## Interface Lifecycle

- All Known Subinterfaces:
    HasUoWFileLifecycle, HasUoWFilesLifecycle<T>
  All Known Implementing Classes:
    HasUoWFileLifecycle.Mixin, HasUoWFilesLifecycle.Mixin

      public interface Lifecycle

  Lifecycle interface for all Composites.

  This Lifecycle interface is a built-in feature of the Zest runtime, similar to the Initializable interface. Any Mixin that implements this interface AND is part of an EntityComposite will have these two methods called upon creation/removal of the EntityComposite instance to/from the EntityStore. Meaning, the create method is called only when the identifiable EntityComposite is created the first time, and not when it is read from its persisted state and created into memory.

  Example;

       public interface System
       {
           Property<User> admin();
       }

       public class SystemAdminMixin<LifeCycle>
           implements System, Lifecyle, ...
       {
            @Structure private UnitOfWork uow;
            @This private Identity meAsIdentity;

            public void create()
            {
                String thisId = meAsIdentity.identity().get();
                EntityBuilder builder = uow.newEntityBuilder( thisId + ":1", UserComposite.class );
                User admin = builder.newInstance();
                admin.set( admin );
            }

            public void remove()
            {
                uow.remove( admin.get() );
            }
       }

       @Mixins( SystemAdminMixin.class )
       public interface SystemEntity extends System, EntityComposite
       {}

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `create()` Creation callback method.
    `void` | `remove()` Removal callback method.

- - ### Method Detail

    - #### create

          void create()
                      throws LifecycleException

      Creation callback method.

      Called by the Zest runtime before the newInstance of the entity completes, before the constraints are checked, allowing for additional initialization.

      Throws:
        `LifecycleException` - if the entity could not be created

    - #### remove

          void remove()
                      throws LifecycleException

      Removal callback method.

      Called by the Zest runtime before the entity is removed from the system, allowing for clean-up operations.

      Throws:
        `LifecycleException` - if the entity could not be removed