polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [10/12] zest-java git commit: ZEST-136 - Massive changes to the Runtime, refactoring the Model and Instance relationship.
Date Thu, 17 Dec 2015 13:16:26 GMT
http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
index c06a811..e997460 100755
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
@@ -70,6 +70,7 @@ import org.apache.zest.runtime.service.ImportedServiceModel;
 import org.apache.zest.runtime.service.ImportedServicesModel;
 import org.apache.zest.runtime.service.ServiceModel;
 import org.apache.zest.runtime.service.ServicesModel;
+import org.apache.zest.runtime.structure.LayerModel;
 import org.apache.zest.runtime.structure.ModuleModel;
 import org.apache.zest.runtime.value.ValueModel;
 import org.apache.zest.runtime.value.ValuesModel;
@@ -504,7 +505,7 @@ public final class ModuleAssemblyImpl
         }
     }
 
-    ModuleModel assembleModule( AssemblyHelper helper )
+    ModuleModel assembleModule( LayerModel layerModel, AssemblyHelper helper )
         throws AssemblyException
     {
         List<TransientModel> transientModels = new ArrayList<>();
@@ -512,6 +513,18 @@ public final class ModuleAssemblyImpl
         List<ValueModel> valueModels = new ArrayList<>();
         List<ServiceModel> serviceModels = new ArrayList<>();
         List<ImportedServiceModel> importedServiceModels = new ArrayList<>();
+        List<EntityModel> entityModels = new ArrayList<>();
+
+        ModuleModel moduleModel = new ModuleModel( name,
+                                                   metaInfo,
+                                                   layerModel,
+                                                   new ActivatorsModel<>( activators ),
+                                                   new TransientsModel( transientModels ),
+                                                   new EntitiesModel( entityModels ),
+                                                   new ObjectsModel( objectModels ),
+                                                   new ValuesModel( valueModels ),
+                                                   new ServicesModel( serviceModels ),
+                                                   new ImportedServicesModel( importedServiceModels ) );
 
         if( name == null )
         {
@@ -520,18 +533,18 @@ public final class ModuleAssemblyImpl
 
         for( TransientAssemblyImpl compositeDeclaration : transientAssemblies.values() )
         {
-            transientModels.add( compositeDeclaration.newTransientModel( metaInfoDeclaration, helper ) );
+            transientModels.add( compositeDeclaration.newTransientModel( moduleModel, metaInfoDeclaration, helper ) );
         }
 
         for( ValueAssemblyImpl valueDeclaration : valueAssemblies.values() )
         {
-            valueModels.add( valueDeclaration.newValueModel( metaInfoDeclaration, helper ) );
+            valueModels.add( valueDeclaration.newValueModel( moduleModel, metaInfoDeclaration, helper ) );
         }
 
-        List<EntityModel> entityModels = new ArrayList<>();
         for( EntityAssemblyImpl entityDeclaration : entityAssemblies.values() )
         {
-            entityModels.add( entityDeclaration.newEntityModel( metaInfoDeclaration,
+            entityModels.add( entityDeclaration.newEntityModel( moduleModel,
+                                                                metaInfoDeclaration,
                                                                 metaInfoDeclaration,
                                                                 metaInfoDeclaration,
                                                                 metaInfoDeclaration,
@@ -540,7 +553,7 @@ public final class ModuleAssemblyImpl
 
         for( ObjectAssemblyImpl objectDeclaration : objectAssemblies.values() )
         {
-            objectDeclaration.addObjectModel( objectModels );
+            objectDeclaration.addObjectModel( moduleModel, objectModels );
         }
 
         for( ServiceAssemblyImpl serviceDeclaration : serviceAssemblies )
@@ -550,7 +563,7 @@ public final class ModuleAssemblyImpl
                 serviceDeclaration.identity = generateId( serviceDeclaration.types() );
             }
 
-            serviceModels.add( serviceDeclaration.newServiceModel( metaInfoDeclaration, helper ) );
+            serviceModels.add( serviceDeclaration.newServiceModel( moduleModel, metaInfoDeclaration, helper ) );
         }
 
         for( ImportedServiceAssemblyImpl importedServiceDeclaration : importedServiceAssemblies.values() )
@@ -558,16 +571,6 @@ public final class ModuleAssemblyImpl
             importedServiceDeclaration.addImportedServiceModel( importedServiceModels );
         }
 
-        ModuleModel moduleModel = new ModuleModel( name,
-                                                   metaInfo,
-                                                   new ActivatorsModel<>( activators ),
-                                                   new TransientsModel( transientModels ),
-                                                   new EntitiesModel( entityModels ),
-                                                   new ObjectsModel( objectModels ),
-                                                   new ValuesModel( valueModels ),
-                                                   new ServicesModel( serviceModels ),
-                                                   new ImportedServicesModel( importedServiceModels ) );
-
         // Check for duplicate service identities
         Set<String> identities = new HashSet<>();
         for( ServiceModel serviceModel : serviceModels )
@@ -601,7 +604,7 @@ public final class ModuleAssemblyImpl
                 )
             {
                 Class<? extends ServiceImporter> serviceFactoryType = importedServiceModel.serviceImporter();
-                ObjectModel objectModel = new ObjectModel( serviceFactoryType, Visibility.module, new MetaInfo() );
+                ObjectModel objectModel = new ObjectModel( moduleModel, serviceFactoryType, Visibility.module, new MetaInfo() );
                 objectModels.add( objectModel );
             }
         }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
index 778ffef..9ea5b6b 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
@@ -21,6 +21,7 @@ import org.apache.zest.api.common.InvalidApplicationException;
 import org.apache.zest.api.common.MetaInfo;
 import org.apache.zest.api.common.Visibility;
 import org.apache.zest.api.composite.Composite;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.bootstrap.ObjectAssembly;
 import org.apache.zest.runtime.object.ObjectModel;
 
@@ -51,11 +52,11 @@ public final class ObjectAssemblyImpl
         return Stream.of( objectType );
     }
 
-    void addObjectModel( List<ObjectModel> objectModels )
+    void addObjectModel( ModuleDescriptor module, List<ObjectModel> objectModels )
     {
         try
         {
-            ObjectModel objectModel = new ObjectModel( objectType, visibility, metaInfo );
+            ObjectModel objectModel = new ObjectModel( module, objectType, visibility, metaInfo );
             objectModels.add( objectModel );
         }
         catch( Throwable e )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
index 255c2d0..e606b10 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
@@ -31,6 +31,7 @@ import org.apache.zest.bootstrap.StateDeclarations;
 import org.apache.zest.functional.Iterables;
 import org.apache.zest.runtime.activation.ActivatorsModel;
 import org.apache.zest.runtime.service.ServiceModel;
+import org.apache.zest.runtime.structure.ModuleModel;
 
 /**
  * Assembly of a Service.
@@ -59,14 +60,14 @@ public final class ServiceAssemblyImpl extends CompositeAssemblyImpl
     }
 
     @SuppressWarnings( { "raw", "unchecked" } )
-    ServiceModel newServiceModel( StateDeclarations stateDeclarations, AssemblyHelper helper )
+    ServiceModel newServiceModel( ModuleModel module, StateDeclarations stateDeclarations, AssemblyHelper helper )
     {
         try
         {
             buildComposite( helper, stateDeclarations );
             List<Class<? extends Activator<?>>> activatorClasses = Iterables.toList(
                 Iterables.<Class<? extends Activator<?>>>flatten( activators, activatorsDeclarations( types.stream() ) ) );
-            return new ServiceModel( types, visibility, metaInfo,
+            return new ServiceModel( module, types, visibility, metaInfo,
                                      new ActivatorsModel( activatorClasses ),
                                      mixinsModel, stateModel, compositeMethodsModel,
                                      identity, instantiateOnStartup );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientAssemblyImpl.java
index 8f3dcdc..100ceab 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientAssemblyImpl.java
@@ -16,6 +16,7 @@ package org.apache.zest.runtime.bootstrap;
 
 import org.apache.zest.api.common.InvalidApplicationException;
 import org.apache.zest.api.composite.TransientComposite;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.bootstrap.StateDeclarations;
 import org.apache.zest.bootstrap.TransientAssembly;
 import org.apache.zest.runtime.composite.TransientModel;
@@ -43,15 +44,16 @@ public final class TransientAssemblyImpl extends CompositeAssemblyImpl
         }
     }
 
-    TransientModel newTransientModel( StateDeclarations stateDeclarations, AssemblyHelper helper )
+    TransientModel newTransientModel( ModuleDescriptor module,
+                                      StateDeclarations stateDeclarations,
+                                      AssemblyHelper helper
+    )
     {
         try
         {
             buildComposite( helper, stateDeclarations );
-            TransientModel transientModel = new TransientModel(
-                types, visibility, metaInfo, mixinsModel, stateModel, compositeMethodsModel );
-
-            return transientModel;
+            return new TransientModel(
+                module, types, visibility, metaInfo, mixinsModel, stateModel, compositeMethodsModel );
         }
         catch( Exception e )
         {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
index 80d692f..af278bd 100755
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
@@ -18,19 +18,33 @@
  */
 package org.apache.zest.runtime.bootstrap;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Member;
+import java.util.List;
 import org.apache.zest.api.association.Association;
 import org.apache.zest.api.association.GenericAssociationInfo;
 import org.apache.zest.api.association.ManyAssociation;
 import org.apache.zest.api.association.NamedAssociation;
-import org.apache.zest.api.common.*;
+import org.apache.zest.api.common.InvalidApplicationException;
+import org.apache.zest.api.common.MetaInfo;
+import org.apache.zest.api.common.Optional;
+import org.apache.zest.api.common.QualifiedName;
+import org.apache.zest.api.common.UseDefaults;
 import org.apache.zest.api.property.GenericPropertyInfo;
 import org.apache.zest.api.property.Property;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.api.util.Annotations;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.api.value.ValueComposite;
 import org.apache.zest.bootstrap.StateDeclarations;
 import org.apache.zest.bootstrap.ValueAssembly;
-import org.apache.zest.runtime.association.*;
+import org.apache.zest.runtime.association.AssociationModel;
+import org.apache.zest.runtime.association.AssociationsModel;
+import org.apache.zest.runtime.association.ManyAssociationModel;
+import org.apache.zest.runtime.association.ManyAssociationsModel;
+import org.apache.zest.runtime.association.NamedAssociationModel;
+import org.apache.zest.runtime.association.NamedAssociationsModel;
 import org.apache.zest.runtime.composite.StateModel;
 import org.apache.zest.runtime.composite.ValueConstraintsInstance;
 import org.apache.zest.runtime.composite.ValueConstraintsModel;
@@ -38,11 +52,6 @@ import org.apache.zest.runtime.property.PropertyModel;
 import org.apache.zest.runtime.value.ValueModel;
 import org.apache.zest.runtime.value.ValueStateModel;
 
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Member;
-import java.util.List;
-
 import static org.apache.zest.api.util.Annotations.isType;
 import static org.apache.zest.api.util.Classes.typeOf;
 
@@ -73,9 +82,9 @@ public final class ValueAssemblyImpl
         return new ValueStateModel( propertiesModel, associationsModel, manyAssociationsModel, namedAssociationsModel );
     }
 
-    ValueModel newValueModel(
-        StateDeclarations stateDeclarations,
-        AssemblyHelper helper
+    ValueModel newValueModel( ModuleDescriptor module,
+                              StateDeclarations stateDeclarations,
+                              AssemblyHelper helper
     )
     {
         try
@@ -86,7 +95,7 @@ public final class ValueAssemblyImpl
             buildComposite( helper, stateDeclarations );
 
             return new ValueModel(
-                types, visibility, metaInfo, mixinsModel, (ValueStateModel) stateModel, compositeMethodsModel );
+                module, types, visibility, metaInfo, mixinsModel, (ValueStateModel) stateModel, compositeMethodsModel );
         }
         catch( Exception e )
         {
@@ -134,7 +143,7 @@ public final class ValueAssemblyImpl
                                               List<Class<?>> constraintClasses
     )
     {
-        List<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
+        List<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
         boolean optional = annotations.stream().anyMatch( isType( Optional.class ) );
         ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations.stream(), GenericPropertyInfo.propertyTypeOf( accessor ), ( (Member) accessor )
             .getName(), optional, constraintClasses, accessor );
@@ -153,7 +162,7 @@ public final class ValueAssemblyImpl
                                                  List<Class<?>> constraintClasses
     )
     {
-        List<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
+        List<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
         boolean optional = annotations.stream().anyMatch( isType( Optional.class ) );
 
         // Constraints for Association references
@@ -181,7 +190,7 @@ public final class ValueAssemblyImpl
                                                          List<Class<?>> constraintClasses
     )
     {
-        List<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
+        List<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
         boolean optional = annotations.stream().anyMatch( isType( Optional.class ) );
 
         // Constraints for entities in ManyAssociation
@@ -208,7 +217,7 @@ public final class ValueAssemblyImpl
                                                            List<Class<?>> constraintClasses
     )
     {
-        List<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
+        List<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
         boolean optional = annotations.stream().anyMatch( isType( Optional.class ) );
 
         // Constraints for entities in NamedAssociation

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/composite/AbstractModifierModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/AbstractModifierModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/AbstractModifierModel.java
index a2458d5..90398e0 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/AbstractModifierModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/AbstractModifierModel.java
@@ -18,9 +18,9 @@ import java.lang.reflect.Array;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.util.function.IntFunction;
 import java.util.stream.Stream;
 import org.apache.zest.api.common.ConstructionException;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
 import org.apache.zest.runtime.injection.Dependencies;
@@ -28,7 +28,6 @@ import org.apache.zest.runtime.injection.DependencyModel;
 import org.apache.zest.runtime.injection.InjectedFieldsModel;
 import org.apache.zest.runtime.injection.InjectedMethodsModel;
 import org.apache.zest.runtime.injection.InjectionContext;
-import org.apache.zest.spi.module.ModuleSpi;
 
 import static org.apache.zest.api.util.Classes.RAW_CLASS;
 import static org.apache.zest.api.util.Classes.interfacesOf;
@@ -99,13 +98,13 @@ public abstract class AbstractModifierModel
     }
 
     // Context
-    public InvocationHandler newInstance( ModuleSpi moduleInstance,
+    public InvocationHandler newInstance( ModuleDescriptor module,
                                           InvocationHandler next,
                                           ProxyReferenceInvocationHandler proxyHandler,
                                           Method method
     )
     {
-        InjectionContext injectionContext = new InjectionContext( moduleInstance, wrapNext( next ), proxyHandler );
+        InjectionContext injectionContext = new InjectionContext( module, wrapNext( next ), proxyHandler );
 
         Object modifier = constructorsModel.newInstance( injectionContext );
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
index 7349cfa..9cfe321 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
@@ -26,6 +26,7 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import org.apache.zest.api.common.ConstructionException;
 import org.apache.zest.api.composite.MethodDescriptor;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.api.util.NullArgumentException;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
@@ -99,12 +100,12 @@ public final class CompositeMethodModel
     }
 
     // Context
-    public Object invoke( Object composite, Object[] params, MixinsInstance mixins, ModuleSpi moduleInstance )
+    public Object invoke( Object composite, Object[] params, MixinsInstance mixins, ModuleDescriptor module )
         throws Throwable
     {
         constraintsInstance.checkValid( composite, method, params );
 
-        CompositeMethodInstance methodInstance = getInstance( moduleInstance );
+        CompositeMethodInstance methodInstance = getInstance( module );
         try
         {
             return mixins.invoke( composite, params, methodInstance );
@@ -115,30 +116,30 @@ public final class CompositeMethodModel
         }
     }
 
-    private CompositeMethodInstance getInstance( ModuleSpi moduleInstance )
+    private CompositeMethodInstance getInstance( ModuleDescriptor module )
     {
         CompositeMethodInstance methodInstance = instancePool.obtainInstance();
         if( methodInstance == null )
         {
-            methodInstance = newCompositeMethodInstance( moduleInstance );
+            methodInstance = newCompositeMethodInstance( module );
         }
 
         return methodInstance;
     }
 
-    private CompositeMethodInstance newCompositeMethodInstance( ModuleSpi moduleInstance )
+    private CompositeMethodInstance newCompositeMethodInstance( ModuleDescriptor module )
         throws ConstructionException
     {
         FragmentInvocationHandler mixinInvocationHandler = mixins.newInvocationHandler( method );
         InvocationHandler invoker = mixinInvocationHandler;
         if( concerns != ConcernsModel.EMPTY_CONCERNS )
         {
-            ConcernsInstance concernsInstance = concerns.newInstance( method, moduleInstance, mixinInvocationHandler );
+            ConcernsInstance concernsInstance = concerns.newInstance( method, module, mixinInvocationHandler );
             invoker = concernsInstance;
         }
         if( sideEffects != SideEffectsModel.EMPTY_SIDEEFFECTS )
         {
-            SideEffectsInstance sideEffectsInstance = sideEffects.newInstance( method, moduleInstance, invoker );
+            SideEffectsInstance sideEffectsInstance = sideEffects.newInstance( method, module, invoker );
             invoker = sideEffectsInstance;
         }
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodsModel.java
index d3915c1..d74ab38 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodsModel.java
@@ -19,13 +19,11 @@ import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.stream.Stream;
 import org.apache.zest.api.composite.MissingMethodException;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
 import org.apache.zest.runtime.injection.Dependencies;
 import org.apache.zest.runtime.injection.DependencyModel;
-import org.apache.zest.spi.module.ModuleSpi;
-
-import static org.apache.zest.functional.Iterables.map;
 
 /**
  * Model for Composite methods. This includes both private and public methods.
@@ -56,7 +54,7 @@ public final class CompositeMethodsModel
                           Object proxy,
                           Method method,
                           Object[] args,
-                          ModuleSpi moduleInstance
+                          ModuleDescriptor moduleInstance
     )
         throws Throwable
     {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java
index 7bd02ef..e75166e 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java
@@ -27,12 +27,12 @@ import org.apache.zest.api.common.Visibility;
 import org.apache.zest.api.composite.Composite;
 import org.apache.zest.api.composite.CompositeDescriptor;
 import org.apache.zest.api.composite.InvalidCompositeException;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.Iterables;
 import org.apache.zest.functional.VisitableHierarchy;
 import org.apache.zest.runtime.injection.Dependencies;
 import org.apache.zest.runtime.injection.DependencyModel;
-import org.apache.zest.spi.module.ModuleSpi;
 
 import static java.lang.reflect.Proxy.newProxyInstance;
 import static org.apache.zest.functional.Iterables.first;
@@ -53,8 +53,10 @@ public abstract class CompositeModel
     private volatile Class<?> primaryType;
     protected Class<? extends Composite> proxyClass;
     protected Constructor<? extends Composite> proxyConstructor;
+    protected ModuleDescriptor module;
 
-    protected CompositeModel( final List<Class<?>> types,
+    protected CompositeModel( final ModuleDescriptor module,
+                              final List<Class<?>> types,
                               final Visibility visibility,
                               final MetaInfo metaInfo,
                               final MixinsModel mixinsModel,
@@ -62,6 +64,7 @@ public abstract class CompositeModel
                               final CompositeMethodsModel compositeMethodsModel
     )
     {
+        this.module = module;
         this.types = new LinkedHashSet<>( types );
         this.visibility = visibility;
         this.metaInfo = metaInfo;
@@ -205,12 +208,17 @@ public abstract class CompositeModel
     public final Object invoke( MixinsInstance mixins,
                                 Object proxy,
                                 Method method,
-                                Object[] args,
-                                ModuleSpi moduleInstance
+                                Object[] args
     )
         throws Throwable
     {
-        return compositeMethodsModel.invoke( mixins, proxy, method, args, moduleInstance );
+        return compositeMethodsModel.invoke( mixins, proxy, method, args, module );
+    }
+
+    @Override
+    public ModuleDescriptor module()
+    {
+        return module;
     }
 
     public Composite newProxy( InvocationHandler invocationHandler )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConcernsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConcernsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConcernsModel.java
index 11f91ad..bea4499 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConcernsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConcernsModel.java
@@ -20,6 +20,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.stream.Stream;
 import org.apache.zest.api.concern.ConcernsDescriptor;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.Iterables;
 import org.apache.zest.functional.VisitableHierarchy;
@@ -50,7 +51,7 @@ public final class ConcernsModel
     }
 
     // Context
-    public ConcernsInstance newInstance( Method method, ModuleSpi moduleInstance,
+    public ConcernsInstance newInstance( Method method, ModuleDescriptor module,
                                          FragmentInvocationHandler mixinInvocationHandler
     )
     {
@@ -60,7 +61,7 @@ public final class ConcernsModel
         {
             ConcernModel concernModel = concernsFor.get( i );
 
-            nextConcern = concernModel.newInstance( moduleInstance, nextConcern, proxyHandler, method );
+            nextConcern = concernModel.newInstance( module, nextConcern, proxyHandler, method );
         }
 
         return new ConcernsInstance( nextConcern, mixinInvocationHandler, proxyHandler );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/composite/SideEffectsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/SideEffectsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/SideEffectsModel.java
index 26d2afa..709a26a 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/SideEffectsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/SideEffectsModel.java
@@ -21,12 +21,11 @@ import java.util.Collections;
 import java.util.List;
 import java.util.stream.Stream;
 import org.apache.zest.api.sideeffect.SideEffectsDescriptor;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
-import org.apache.zest.functional.Iterables;
 import org.apache.zest.functional.VisitableHierarchy;
 import org.apache.zest.runtime.injection.Dependencies;
 import org.apache.zest.runtime.injection.DependencyModel;
-import org.apache.zest.spi.module.ModuleSpi;
 
 /**
  * JAVADOC
@@ -51,14 +50,14 @@ public final class SideEffectsModel
     }
 
     // Context
-    public SideEffectsInstance newInstance( Method method, ModuleSpi moduleInstance, InvocationHandler invoker )
+    public SideEffectsInstance newInstance( Method method, ModuleDescriptor module, InvocationHandler invoker )
     {
         ProxyReferenceInvocationHandler proxyHandler = new ProxyReferenceInvocationHandler();
         SideEffectInvocationHandlerResult result = new SideEffectInvocationHandlerResult();
         List<InvocationHandler> sideEffects = new ArrayList<InvocationHandler>( sideEffectModels.size() );
         for( SideEffectModel sideEffectModel : sideEffectModels )
         {
-            InvocationHandler sideEffect = sideEffectModel.newInstance( moduleInstance, result, proxyHandler, method );
+            InvocationHandler sideEffect = sideEffectModel.newInstance( module, result, proxyHandler, method );
             sideEffects.add( sideEffect );
         }
         return new SideEffectsInstance( sideEffects, result, proxyHandler, invoker );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java
index 2b0570c..c70fc68 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java
@@ -19,8 +19,6 @@ import org.apache.zest.api.composite.CompositeInstance;
 import org.apache.zest.api.composite.TransientBuilder;
 import org.apache.zest.api.composite.TransientDescriptor;
 import org.apache.zest.runtime.property.PropertyInstance;
-import org.apache.zest.spi.structure.ModelModule;
-import org.apache.zest.spi.module.ModuleSpi;
 
 /**
  * JAVADOC
@@ -28,7 +26,6 @@ import org.apache.zest.spi.module.ModuleSpi;
 public final class TransientBuilderInstance<T>
     implements TransientBuilder<T>
 {
-    private ModuleSpi module;
     private TransientModel model;
 
     // lazy initialized in accessor
@@ -39,13 +36,12 @@ public final class TransientBuilderInstance<T>
 
     private TransientStateInstance state;
 
-    public TransientBuilderInstance( ModelModule<TransientDescriptor> modelModule,
+    public TransientBuilderInstance( TransientDescriptor model,
                                      TransientStateInstance state,
                                      UsesInstance uses
     )
     {
-        this.model = (TransientModel) modelModule.model();
-        this.module = modelModule.module();
+        this.model = (TransientModel) model;
         this.state = state;
         this.uses = uses;
     }
@@ -63,7 +59,7 @@ public final class TransientBuilderInstance<T>
         // Instantiate given value type
         if( prototypeInstance == null )
         {
-            prototypeInstance = model.newInstance( module, uses, state );
+            prototypeInstance = model.newInstance( uses, state );
         }
 
         return prototypeInstance.<T>proxy();
@@ -75,7 +71,7 @@ public final class TransientBuilderInstance<T>
         // Instantiate given value type
         if( prototypeInstance == null )
         {
-            prototypeInstance = model.newInstance( module, uses, state );
+            prototypeInstance = model.newInstance( uses, state );
         }
 
         return prototypeInstance.newProxy( mixinType );
@@ -94,8 +90,7 @@ public final class TransientBuilderInstance<T>
 
         model.checkConstraints( state );
 
-        CompositeInstance compositeInstance =
-            model.newInstance( module, uses, state );
+        CompositeInstance compositeInstance = model.newInstance( uses, state );
         return compositeInstance.<T>proxy();
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientInstance.java
index 5531d52..75f7266 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientInstance.java
@@ -25,10 +25,8 @@ import org.apache.zest.api.ZestAPI;
 import org.apache.zest.api.composite.Composite;
 import org.apache.zest.api.composite.CompositeInstance;
 import org.apache.zest.api.property.StateHolder;
-import org.apache.zest.api.structure.Layer;
-import org.apache.zest.api.structure.Module;
-import org.apache.zest.runtime.structure.ModuleInstance;
-import org.apache.zest.spi.module.ModuleSpi;
+import org.apache.zest.api.structure.LayerDescriptor;
+import org.apache.zest.api.structure.ModuleDescriptor;
 
 /**
  * InvocationHandler for proxy objects.
@@ -46,16 +44,13 @@ public class TransientInstance
     protected final Object[] mixins;
     protected StateHolder state;
     protected final CompositeModel compositeModel;
-    private final ModuleSpi moduleInstance;
 
     public TransientInstance( CompositeModel compositeModel,
-                              ModuleSpi moduleInstance,
                               Object[] mixins,
                               StateHolder state
     )
     {
         this.compositeModel = compositeModel;
-        this.moduleInstance = moduleInstance;
         this.mixins = mixins;
         this.state = state;
 
@@ -66,7 +61,7 @@ public class TransientInstance
     public Object invoke( Object proxy, Method method, Object[] args )
         throws Throwable
     {
-        return compositeModel.invoke( this, proxy, method, args, moduleInstance );
+        return compositeModel.invoke( this, proxy, method, args );
     }
 
     @Override
@@ -87,7 +82,7 @@ public class TransientInstance
     public Object invokeComposite( Method method, Object[] args )
         throws Throwable
     {
-        return compositeModel.invoke( this, proxy, method, args, moduleInstance );
+        return compositeModel.invoke( this, proxy, method, args );
     }
 
     @Override
@@ -109,14 +104,14 @@ public class TransientInstance
     }
 
     @Override
-    public Module module()
+    public ModuleDescriptor module()
     {
-        return moduleInstance;
+        return compositeModel.module();
     }
 
-    public Layer layer()
+    public LayerDescriptor layer()
     {
-        return ( (ModuleInstance) moduleInstance ).layerInstance();
+        return compositeModel.module().layer();
     }
 
     @Override
@@ -217,7 +212,7 @@ public class TransientInstance
                    "mixins=" + Arrays.asList( mixins ) +
                    ", state=" + state +
                    ", compositeModel=" + compositeModel +
-                   ", module=" + moduleInstance +
+                   ", module=" + module() +
                    '}';
         }
         return buffer.toString();

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientModel.java
index cc3d343..97475e9 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientModel.java
@@ -19,6 +19,7 @@ import org.apache.zest.api.common.MetaInfo;
 import org.apache.zest.api.common.Visibility;
 import org.apache.zest.api.composite.TransientDescriptor;
 import org.apache.zest.api.constraint.ConstraintViolationException;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.runtime.injection.InjectionContext;
 import org.apache.zest.spi.module.ModuleSpi;
 
@@ -28,23 +29,23 @@ import org.apache.zest.spi.module.ModuleSpi;
 public class TransientModel extends CompositeModel
     implements TransientDescriptor
 {
-    public TransientModel( List<Class<?>> types, final Visibility visibility,
+    public TransientModel( ModuleDescriptor module,
+                           List<Class<?>> types, final Visibility visibility,
                            final MetaInfo metaInfo,
                            final MixinsModel mixinsModel,
                            final StateModel stateModel,
                            final CompositeMethodsModel compositeMethodsModel
     )
     {
-        super( types, visibility, metaInfo, mixinsModel, stateModel, compositeMethodsModel );
+        super( module, types, visibility, metaInfo, mixinsModel, stateModel, compositeMethodsModel );
     }
 
-    public TransientInstance newInstance( ModuleSpi moduleInstance,
-                                          UsesInstance uses,
+    public TransientInstance newInstance( UsesInstance uses,
                                           TransientStateInstance state
     )
     {
         Object[] mixins = mixinsModel.newMixinHolder();
-        TransientInstance compositeInstance = new TransientInstance( this, moduleInstance, mixins, state );
+        TransientInstance compositeInstance = new TransientInstance( this, mixins, state );
 
         // Instantiate all mixins
         int i = 0;

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
index 15c8524..6149700 100755
--- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
@@ -30,6 +30,7 @@ import org.apache.zest.api.entity.EntityComposite;
 import org.apache.zest.api.entity.EntityReference;
 import org.apache.zest.api.entity.Identity;
 import org.apache.zest.api.entity.LifecycleException;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.api.unitofwork.NoSuchEntityException;
 import org.apache.zest.api.unitofwork.UnitOfWork;
 import org.apache.zest.api.unitofwork.UnitOfWorkException;
@@ -37,7 +38,6 @@ import org.apache.zest.runtime.composite.CompositeMethodInstance;
 import org.apache.zest.runtime.composite.MixinsInstance;
 import org.apache.zest.spi.entity.EntityState;
 import org.apache.zest.spi.entity.EntityStatus;
-import org.apache.zest.spi.module.ModuleSpi;
 
 import static java.util.stream.Collectors.toList;
 
@@ -54,7 +54,6 @@ public final class EntityInstance
 
     private final EntityComposite proxy;
     private final UnitOfWork uow;
-    private final ModuleSpi moduleInstance;
     private final EntityModel entityModel;
     private final EntityReference identity;
     private final EntityState entityState;
@@ -63,13 +62,11 @@ public final class EntityInstance
     private EntityStateInstance state;
 
     public EntityInstance( UnitOfWork uow,
-                           ModuleSpi moduleInstance,
                            EntityModel entityModel,
                            EntityState entityState
     )
     {
         this.uow = uow;
-        this.moduleInstance = moduleInstance;
         this.entityModel = entityModel;
         this.identity = entityState.identity();
         this.entityState = entityState;
@@ -81,7 +78,7 @@ public final class EntityInstance
     public Object invoke( Object proxy, Method method, Object[] args )
         throws Throwable
     {
-        return entityModel.invoke( this, this.proxy, method, args, moduleInstance );
+        return entityModel.invoke( this, this.proxy, method, args );
     }
 
     public EntityReference identity()
@@ -113,7 +110,7 @@ public final class EntityInstance
     public Object invokeComposite( Method method, Object[] args )
         throws Throwable
     {
-        return entityModel.invoke( this, proxy, method, args, moduleInstance );
+        return entityModel.invoke( this, proxy, method, args );
     }
 
     @Override
@@ -134,9 +131,9 @@ public final class EntityInstance
     }
 
     @Override
-    public ModuleSpi module()
+    public ModuleDescriptor module()
     {
-        return moduleInstance;
+        return entityModel.module();
     }
 
     public UnitOfWork unitOfWork()

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java
index bac3936..209294b 100755
--- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java
@@ -27,6 +27,7 @@ import org.apache.zest.api.entity.Identity;
 import org.apache.zest.api.entity.Queryable;
 import org.apache.zest.api.property.PropertyDescriptor;
 import org.apache.zest.api.property.StateHolder;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.api.unitofwork.EntityCompositeAlreadyExistsException;
 import org.apache.zest.api.util.Annotations;
 import org.apache.zest.runtime.composite.CompositeMethodsModel;
@@ -60,7 +61,8 @@ public final class EntityModel extends CompositeModel
 
     private final boolean queryable;
 
-    public EntityModel( List<Class<?>> types,
+    public EntityModel( ModuleDescriptor module,
+                        List<Class<?>> types,
                         Visibility visibility,
                         MetaInfo info,
                         EntityMixinsModel mixinsModel,
@@ -68,7 +70,7 @@ public final class EntityModel extends CompositeModel
                         CompositeMethodsModel compositeMethodsModel
     )
     {
-        super( types, visibility, info, mixinsModel, stateModel, compositeMethodsModel );
+        super( module, types, visibility, info, mixinsModel, stateModel, compositeMethodsModel );
 
         this.queryable = types.stream()
             .flatMap( Annotations.ANNOTATIONS_OF )
@@ -92,7 +94,7 @@ public final class EntityModel extends CompositeModel
 
     public EntityInstance newInstance( ModuleUnitOfWork uow, ModuleSpi moduleInstance, EntityState state )
     {
-        return new EntityInstance( uow, moduleInstance, this, state );
+        return new EntityInstance( uow, this, state );
     }
 
     public Object[] newMixinHolder()
@@ -133,7 +135,7 @@ public final class EntityModel extends CompositeModel
         }
     }
 
-    public void initState( ModuleSpi module, EntityState entityState )
+    public void initState( ModuleDescriptor module, EntityState entityState )
     {
         // Set new properties to default value
         state().properties().forEach( propertyDescriptor -> {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectionContext.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectionContext.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectionContext.java
index f9cefac..aeaf81b 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectionContext.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectionContext.java
@@ -16,17 +16,16 @@ package org.apache.zest.runtime.injection;
 
 import org.apache.zest.api.composite.CompositeInstance;
 import org.apache.zest.api.property.StateHolder;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.runtime.composite.ProxyReferenceInvocationHandler;
 import org.apache.zest.runtime.composite.UsesInstance;
-import org.apache.zest.runtime.structure.ModuleInstance;
-import org.apache.zest.spi.module.ModuleSpi;
 
 /**
  * JAVADOC
  */
 public final class InjectionContext
 {
-    private final ModuleSpi moduleInstance;
+    private final ModuleDescriptor module;
     private CompositeInstance compositeInstance;
     private UsesInstance uses;
     private StateHolder state;
@@ -38,37 +37,37 @@ public final class InjectionContext
 
     public InjectionContext( CompositeInstance compositeInstance, UsesInstance uses, StateHolder state )
     {
-        this.moduleInstance = (ModuleInstance) compositeInstance.module();
+        this.module = compositeInstance.module();
         this.compositeInstance = compositeInstance;
         this.uses = uses;
         this.state = state;
     }
 
     // For concerns and side-effects
-    public InjectionContext( ModuleSpi moduleInstance, Object next, ProxyReferenceInvocationHandler proxyHandler )
+    public InjectionContext( ModuleDescriptor module, Object next, ProxyReferenceInvocationHandler proxyHandler )
     {
-        this.moduleInstance = moduleInstance;
+        this.module = module;
         this.next = next;
         this.proxyHandler = proxyHandler;
     }
 
-    public InjectionContext( ModuleSpi moduleInstance, UsesInstance uses )
+    public InjectionContext( ModuleDescriptor module, UsesInstance uses )
     {
-        this.moduleInstance = moduleInstance;
+        this.module = module;
         this.uses = uses;
     }
 
     // For inner classes
-    public InjectionContext( ModuleSpi moduleInstance, UsesInstance uses, Object instance )
+    public InjectionContext( ModuleDescriptor module, UsesInstance uses, Object instance )
     {
-        this.moduleInstance = moduleInstance;
+        this.module = module;
         this.uses = uses;
         this.instance = instance;
     }
 
-    public ModuleSpi module()
+    public ModuleDescriptor module()
     {
-        return moduleInstance;
+        return module;
     }
 
     public CompositeInstance compositeInstance()
@@ -111,7 +110,7 @@ public final class InjectionContext
     {
         return "InjectionContext{" +
                "compositeInstance=" + compositeInstance +
-               ", module=" + moduleInstance +
+               ", module=" + module +
                ", uses=" + uses +
                ", state=" + state +
                ", next=" + next +

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
index 9b65780..4a7d455 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
@@ -196,11 +196,11 @@ public final class ServiceInjectionProviderFactory
             {
                 if( serviceQualifier == null )
                 {
-                    return context.module().findService( serviceType );
+                    return context.module().instance().findService( serviceType );
                 }
                 else
                 {
-                    return Iterables.first( Iterables.filter( serviceQualifier, context.module()
+                    return Iterables.first( Iterables.filter( serviceQualifier, context.module().instance()
                         .findServices( serviceType ) ) );
                 }
             }
@@ -214,11 +214,11 @@ public final class ServiceInjectionProviderFactory
         {
             if( serviceQualifier == null )
             {
-                return context.module().findServices( serviceType );
+                return context.module().instance().findServices( serviceType );
             }
             else
             {
-                return Iterables.filter( serviceQualifier, context.module().findServices( serviceType ) );
+                return Iterables.filter( serviceQualifier, context.module().instance().findServices( serviceType ) );
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/StructureInjectionProviderFactory.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/StructureInjectionProviderFactory.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/StructureInjectionProviderFactory.java
index 1fbb3a3..260aa26 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/StructureInjectionProviderFactory.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/StructureInjectionProviderFactory.java
@@ -24,8 +24,11 @@ import org.apache.zest.api.object.ObjectFactory;
 import org.apache.zest.api.query.QueryBuilderFactory;
 import org.apache.zest.api.service.ServiceFinder;
 import org.apache.zest.api.structure.Application;
+import org.apache.zest.api.structure.ApplicationDescriptor;
 import org.apache.zest.api.structure.Layer;
+import org.apache.zest.api.structure.LayerDescriptor;
 import org.apache.zest.api.structure.Module;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.api.unitofwork.UnitOfWorkFactory;
 import org.apache.zest.api.value.ValueBuilderFactory;
 import org.apache.zest.bootstrap.InvalidInjectionException;
@@ -34,8 +37,7 @@ import org.apache.zest.runtime.injection.InjectionContext;
 import org.apache.zest.runtime.injection.InjectionProvider;
 import org.apache.zest.runtime.injection.InjectionProviderFactory;
 import org.apache.zest.runtime.model.Resolution;
-import org.apache.zest.runtime.structure.ModuleInstance;
-import org.apache.zest.spi.module.ModuleSpi;
+import org.apache.zest.runtime.structure.ApplicationInstance;
 
 public final class StructureInjectionProviderFactory
     implements InjectionProviderFactory
@@ -69,49 +71,56 @@ public final class StructureInjectionProviderFactory
             Class clazz = (Class) type1;
             if( clazz.equals( TransientBuilderFactory.class ) )
             {
-                return context.module();
+                return context.module().instance();
             }
             else if( clazz.equals( ObjectFactory.class ) )
             {
-                return context.module();
+                return context.module().instance();
             }
             else if( clazz.equals( ValueBuilderFactory.class ) )
             {
-                return context.module();
+                return context.module().instance();
             }
             else if( clazz.equals( UnitOfWorkFactory.class ) )
             {
-                return context.module().unitOfWorkFactory();
+                return context.module().instance().unitOfWorkFactory();
             }
             else if( clazz.equals( QueryBuilderFactory.class ) )
             {
-                return context.module();
+                return context.module().instance();
             }
             else if( clazz.equals( ServiceFinder.class ) )
             {
-                return context.module();
+                return context.module().instance();
             }
             else if( Module.class.isAssignableFrom( clazz ) )
             {
-                return context.module();
+                return context.module().instance();
             }
-            else if( ModuleSpi.class.isAssignableFrom( clazz ) )
+            else if( ModuleDescriptor.class.isAssignableFrom( clazz ) )
             {
                 return context.module();
             }
             else if( Layer.class.isAssignableFrom( clazz ) )
             {
-                return (( ModuleInstance) context.module()).layerInstance();
+                return context.module().layer().instance();
+            }
+            else if( LayerDescriptor.class.isAssignableFrom( clazz ) )
+            {
+                return context.module().layer();
             }
             else if( Application.class.isAssignableFrom( clazz ) )
             {
-                return (( ModuleInstance) context.module()).layerInstance().applicationInstance();
+                return context.module().layer().instance().application();
+            }
+            else if( ApplicationDescriptor.class.isAssignableFrom( clazz ) )
+            {
+                return context.module().layer().instance().application().descriptor();
             }
             else if( ZestAPI.class.isAssignableFrom( clazz ) )
             {
-                return (( ModuleInstance) context.module()).layerInstance().applicationInstance().runtime();
+                return (( ApplicationInstance) context.module().layer().instance().application()).runtime();
             }
-
             return null;
         }
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/UsesInjectionProviderFactory.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/UsesInjectionProviderFactory.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/UsesInjectionProviderFactory.java
index 0e5ed5a..0826e17 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/UsesInjectionProviderFactory.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/UsesInjectionProviderFactory.java
@@ -71,7 +71,7 @@ public final class UsesInjectionProviderFactory
             {
                 // No @Uses object provided
                 // Try instantiating a Transient or Object for the given type
-                Module moduleInstance = context.module();
+                Module moduleInstance = context.module().instance();
 
                 try
                 {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectModel.java
index 8764fba..27eb9dc 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectModel.java
@@ -21,6 +21,7 @@ import org.apache.zest.api.common.Visibility;
 import org.apache.zest.api.mixin.Initializable;
 import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.object.ObjectDescriptor;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
 import org.apache.zest.runtime.composite.ConstructorsModel;
@@ -34,6 +35,7 @@ import org.apache.zest.runtime.injection.InjectionContext;
 public final class ObjectModel
     implements ObjectDescriptor, VisitableHierarchy<Object, Object>
 {
+    private final ModuleDescriptor module;
     private final Class<?> objectType;
     private final Visibility visibility;
     private final MetaInfo metaInfo;
@@ -41,11 +43,13 @@ public final class ObjectModel
     private final InjectedFieldsModel injectedFieldsModel;
     private final InjectedMethodsModel injectedMethodsModel;
 
-    public ObjectModel( Class<?> objectType,
+    public ObjectModel( ModuleDescriptor module,
+                        Class<?> objectType,
                         Visibility visibility,
                         MetaInfo metaInfo
     )
     {
+        this.module = module;
         this.objectType = objectType;
         this.visibility = visibility;
         this.metaInfo = metaInfo;
@@ -69,6 +73,12 @@ public final class ObjectModel
     }
 
     @Override
+    public ModuleDescriptor module()
+    {
+        return module;
+    }
+
+    @Override
     public <T> T metaInfo( Class<T> infoType )
     {
         return metaInfo.get( infoType );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectsModel.java
index e610807..9895468 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectsModel.java
@@ -49,7 +49,7 @@ public class ObjectsModel
         return visitor.visitLeave( this );
     }
 
-    public Stream<ObjectModel> stream()
+    public Stream<ObjectModel> models()
     {
         return objectModels.stream();
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/property/PropertyModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/property/PropertyModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/property/PropertyModel.java
index 571bdb1..3f2923c 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/property/PropertyModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/property/PropertyModel.java
@@ -33,6 +33,7 @@ import org.apache.zest.api.property.InvalidPropertyTypeException;
 import org.apache.zest.api.property.Property;
 import org.apache.zest.api.property.PropertyDescriptor;
 import org.apache.zest.api.structure.Module;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.api.type.Serialization;
 import org.apache.zest.api.type.ValueCompositeType;
 import org.apache.zest.api.type.ValueType;
@@ -163,7 +164,7 @@ public class PropertyModel
     }
 
     @Override
-    public Object initialValue( Module module )
+    public Object initialValue( ModuleDescriptor module )
     {
         // Use supplied value from assembly
         Object value = initialValue;
@@ -173,7 +174,7 @@ public class PropertyModel
         {
             if( valueType instanceof ValueCompositeType )
             {
-                return module.newValue( valueType().types().findFirst().orElse( null ) );
+                return module.instance().newValue( valueType().types().findFirst().orElse( null ) );
             }
             else
             {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServiceModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServiceModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServiceModel.java
index 648f5ba..f3bf992 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServiceModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServiceModel.java
@@ -27,7 +27,7 @@ import org.apache.zest.api.common.Visibility;
 import org.apache.zest.api.service.ImportedServiceDescriptor;
 import org.apache.zest.api.service.ServiceImporter;
 import org.apache.zest.api.service.ServiceImporterException;
-import org.apache.zest.api.structure.Module;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
 import org.apache.zest.runtime.activation.ActivatorsInstance;
@@ -89,6 +89,12 @@ public final class ImportedServiceModel
     }
 
     @Override
+    public ModuleDescriptor module()
+    {
+        return null;
+    }
+
+    @Override
     public <T> T metaInfo( Class<T> infoType )
     {
         return metaInfo.get( infoType );
@@ -119,7 +125,7 @@ public final class ImportedServiceModel
     }
 
     @SuppressWarnings( { "raw", "unchecked" } )
-    public ActivatorsInstance<?> newActivatorsInstance( Module module )
+    public ActivatorsInstance<?> newActivatorsInstance( ModuleDescriptor module )
         throws Exception
     {
         return new ActivatorsInstance( activatorsModel.newInstances( module ) );
@@ -143,11 +149,11 @@ public final class ImportedServiceModel
     }
 
     @SuppressWarnings( { "raw", "unchecked" } )
-    public <T> ImportedServiceInstance<T> importInstance( Module module )
+    public <T> ImportedServiceInstance<T> importInstance( ModuleDescriptor module )
     {
         try
         {
-            ServiceImporter importer = module.newObject( serviceImporter );
+            ServiceImporter importer = module.instance().newObject( serviceImporter );
             T instance = (T) importer.importService( this );
             return new ImportedServiceInstance<>( instance, importer );
         }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServiceReferenceInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServiceReferenceInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServiceReferenceInstance.java
index a44c7f5..b77370a 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServiceReferenceInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServiceReferenceInstance.java
@@ -27,7 +27,7 @@ import org.apache.zest.api.activation.PassivationException;
 import org.apache.zest.api.service.ServiceImporterException;
 import org.apache.zest.api.service.ServiceReference;
 import org.apache.zest.api.service.ServiceUnavailableException;
-import org.apache.zest.api.structure.Module;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.runtime.activation.ActivationDelegate;
 
 /**
@@ -37,6 +37,7 @@ import org.apache.zest.runtime.activation.ActivationDelegate;
  * to handle service passivation and unavailability correctly, any proxying must be done in the
  * service importer.
  * </p>
+ *
  * @param <T> Service Type
  */
 public final class ImportedServiceReferenceInstance<T>
@@ -44,12 +45,12 @@ public final class ImportedServiceReferenceInstance<T>
 {
     private volatile ImportedServiceInstance<T> serviceInstance;
     private T instance;
-    private final Module module;
+    private final ModuleDescriptor module;
     private final ImportedServiceModel serviceModel;
     private final ActivationDelegate activation = new ActivationDelegate( this );
     private boolean active = false;
 
-    public ImportedServiceReferenceInstance( ImportedServiceModel serviceModel, Module module )
+    public ImportedServiceReferenceInstance( ImportedServiceModel serviceModel, ModuleDescriptor module )
     {
         this.module = module;
         this.serviceModel = serviceModel;
@@ -68,7 +69,7 @@ public final class ImportedServiceReferenceInstance<T>
     }
 
     @Override
-    public <T> T metaInfo( Class<T> infoType )
+    public <M> M metaInfo( Class<M> infoType )
     {
         return serviceModel.metaInfo( infoType );
     }
@@ -102,14 +103,7 @@ public final class ImportedServiceReferenceInstance<T>
         {
             try
             {
-                activation.passivate( new Runnable()
-                {
-                    @Override
-                    public void run()
-                    {
-                        active = false;
-                    }
-                } );
+                activation.passivate( () -> active = false );
             }
             finally
             {
@@ -139,7 +133,7 @@ public final class ImportedServiceReferenceInstance<T>
         }
     }
 
-    public Module module()
+    public ModuleDescriptor module()
     {
         return module;
     }
@@ -159,14 +153,12 @@ public final class ImportedServiceReferenceInstance<T>
 
                     try
                     {
-                        activation.activate( serviceModel.newActivatorsInstance( module ), serviceInstance, new Runnable()
-                        {
-                            @Override
-                            public void run()
-                            {
+                        activation.activate(
+                            serviceModel.newActivatorsInstance( module ),
+                            serviceInstance, () -> {
                                 active = true;
                             }
-                        } );
+                        );
                     }
                     catch( Exception e )
                     {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServicesInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServicesInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServicesInstance.java
index 7faf290..4178dc7 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServicesInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServicesInstance.java
@@ -55,7 +55,7 @@ public class ImportedServicesInstance
 
     public Stream<ImportedServiceModel> models()
     {
-        return servicesModel.stream();
+        return servicesModel.models();
     }
 
     @Override
@@ -112,6 +112,6 @@ public class ImportedServicesInstance
 
     public Stream<? extends ImportedServiceDescriptor> stream()
     {
-        return servicesModel.stream();
+        return servicesModel.models();
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServicesModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServicesModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServicesModel.java
index 9853830..ea15932 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServicesModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ImportedServicesModel.java
@@ -17,11 +17,10 @@ package org.apache.zest.runtime.service;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Stream;
-import org.apache.zest.api.service.ImportedServiceDescriptor;
 import org.apache.zest.api.service.ServiceReference;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
-import org.apache.zest.runtime.structure.ModuleInstance;
 
 /**
  * JAVADOC
@@ -36,7 +35,7 @@ public class ImportedServicesModel
         this.importedServiceModels = importedServiceModels;
     }
 
-    public ImportedServicesInstance newInstance( ModuleInstance module )
+    public ImportedServicesInstance newInstance( ModuleDescriptor module )
     {
         List<ServiceReference<?>> serviceReferences = new ArrayList<>();
         for( ImportedServiceModel serviceModel : importedServiceModels )
@@ -65,7 +64,7 @@ public class ImportedServicesModel
         return visitor.visitLeave( this );
     }
 
-    public Stream<ImportedServiceModel> stream()
+    public Stream<ImportedServiceModel> models()
     {
         return importedServiceModels.stream();
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceInstance.java
index 6a401d2..451bdfa 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceInstance.java
@@ -25,7 +25,6 @@ import org.apache.zest.api.service.ServiceComposite;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.runtime.composite.TransientInstance;
 import org.apache.zest.runtime.composite.TransientStateInstance;
-import org.apache.zest.runtime.structure.ModuleInstance;
 
 /**
  * JAVADOC
@@ -43,12 +42,11 @@ public class ServiceInstance
     private final boolean hasEnabledConfiguration;
 
     public ServiceInstance( ServiceModel compositeModel,
-                            ModuleInstance moduleInstance,
                             Object[] mixins,
                             TransientStateInstance state
     )
     {
-        super( compositeModel, moduleInstance, mixins, state );
+        super( compositeModel, mixins, state );
 
         implementsServiceAvailable =
             Classes.assignableTypeSpecification( Availability.class ).test( descriptor() );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceModel.java
index 7a3d3d8..11c38b8 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceModel.java
@@ -33,7 +33,7 @@ import org.apache.zest.api.entity.Identity;
 import org.apache.zest.api.injection.scope.This;
 import org.apache.zest.api.property.Property;
 import org.apache.zest.api.service.ServiceDescriptor;
-import org.apache.zest.api.structure.Module;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.runtime.activation.ActivatorsInstance;
@@ -48,7 +48,6 @@ import org.apache.zest.runtime.composite.UsesInstance;
 import org.apache.zest.runtime.injection.DependencyModel;
 import org.apache.zest.runtime.injection.InjectionContext;
 import org.apache.zest.runtime.property.PropertyInstance;
-import org.apache.zest.runtime.structure.ModuleInstance;
 
 import static org.apache.zest.runtime.legacy.Specifications.translate;
 
@@ -77,7 +76,8 @@ public final class ServiceModel extends CompositeModel
     private final ActivatorsModel<?> activatorsModel;
     private final Class configurationType;
 
-    public ServiceModel( List<Class<?>> types,
+    public ServiceModel( ModuleDescriptor module,
+                         List<Class<?>> types,
                          Visibility visibility,
                          MetaInfo metaInfo,
                          ActivatorsModel<?> activatorsModel,
@@ -88,7 +88,7 @@ public final class ServiceModel extends CompositeModel
                          boolean instantiateOnStartup
     )
     {
-        super( types, visibility, metaInfo, mixinsModel, stateModel, compositeMethodsModel );
+        super( module, types, visibility, metaInfo, mixinsModel, stateModel, compositeMethodsModel );
 
         this.identity = identity;
         this.instantiateOnStartup = instantiateOnStartup;
@@ -111,7 +111,7 @@ public final class ServiceModel extends CompositeModel
     }
 
     @SuppressWarnings( { "raw", "unchecked" } )
-    public ActivatorsInstance<?> newActivatorsInstance( Module module )
+    public ActivatorsInstance<?> newActivatorsInstance( ModuleDescriptor module )
         throws Exception
     {
         return new ActivatorsInstance( activatorsModel.newInstances( module ) );
@@ -144,7 +144,7 @@ public final class ServiceModel extends CompositeModel
         return visitor.visitLeave( this );
     }
 
-    public ServiceInstance newInstance( final ModuleInstance module )
+    public ServiceInstance newInstance( final ModuleDescriptor module )
     {
         Object[] mixins = mixinsModel.newMixinHolder();
 
@@ -161,7 +161,7 @@ public final class ServiceModel extends CompositeModel
         } );
 
         TransientStateInstance state = new TransientStateInstance( properties );
-        ServiceInstance compositeInstance = new ServiceInstance( this, module, mixins, state );
+        ServiceInstance compositeInstance = new ServiceInstance( this, mixins, state );
 
         // Instantiate all mixins
         int i = 0;

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceReferenceInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceReferenceInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceReferenceInstance.java
index e7eb325..97928c5 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceReferenceInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceReferenceInstance.java
@@ -34,9 +34,8 @@ import org.apache.zest.api.service.ServiceDescriptor;
 import org.apache.zest.api.service.ServiceImporterException;
 import org.apache.zest.api.service.ServiceReference;
 import org.apache.zest.api.service.ServiceUnavailableException;
-import org.apache.zest.api.structure.Module;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.runtime.activation.ActivationDelegate;
-import org.apache.zest.runtime.structure.ModuleInstance;
 
 /**
  * Implementation of ServiceReference.
@@ -54,12 +53,12 @@ public final class ServiceReferenceInstance<T>
 {
     private volatile ServiceInstance instance;
     private final T serviceProxy;
-    private final ModuleInstance module;
+    private final ModuleDescriptor module;
     private final ServiceModel serviceModel;
     private final ActivationDelegate activation = new ActivationDelegate( this );
     private boolean active = false;
 
-    public ServiceReferenceInstance( ServiceModel serviceModel, ModuleInstance module )
+    public ServiceReferenceInstance( ServiceModel serviceModel, ModuleDescriptor module )
     {
         this.module = module;
         this.serviceModel = serviceModel;
@@ -103,7 +102,7 @@ public final class ServiceReferenceInstance<T>
         return getInstance().isAvailable();
     }
 
-    public Module module()
+    public ModuleDescriptor module()
     {
         return module;
     }
@@ -276,7 +275,7 @@ public final class ServiceReferenceInstance<T>
         }
 
         @Override
-        public Module module()
+        public ModuleDescriptor module()
         {
             return module;
         }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesInstance.java
index 31e6738..3b2bea9 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesInstance.java
@@ -51,9 +51,9 @@ public class ServicesInstance
         }
     }
 
-    public Stream<ServiceModel> models()
+    public Stream<? extends ServiceDescriptor> models()
     {
-        return servicesModel.stream();
+        return servicesModel.models();
     }
 
     @Override
@@ -105,8 +105,13 @@ public class ServicesInstance
         activation.deregisterActivationEventListener( listener );
     }
 
-    public Stream<? extends ServiceDescriptor> stream()
+    public Stream<? extends ServiceDescriptor> descriptors()
     {
-        return servicesModel.stream();
+        return servicesModel.models();
+    }
+
+    public Stream<ServiceReference<?>> references()
+    {
+        return serviceReferences.stream();
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesModel.java
index 4635d42..d8d6929 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesModel.java
@@ -17,10 +17,11 @@ package org.apache.zest.runtime.service;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Stream;
+import org.apache.zest.api.service.ServiceDescriptor;
 import org.apache.zest.api.service.ServiceReference;
+import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
-import org.apache.zest.runtime.structure.ModuleInstance;
 
 /**
  * JAVADOC
@@ -35,7 +36,7 @@ public class ServicesModel
         this.serviceModels = serviceModels;
     }
 
-    public ServicesInstance newInstance( ModuleInstance module )
+    public ServicesInstance newInstance( ModuleDescriptor module )
     {
         List<ServiceReference<?>> serviceReferences = new ArrayList<>();
         for( ServiceModel serviceModel : serviceModels )
@@ -64,7 +65,7 @@ public class ServicesModel
         return visitor.visitLeave( this );
     }
 
-    public Stream<ServiceModel> stream()
+    public Stream<? extends ServiceDescriptor> models()
     {
         return serviceModels.stream();
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/structure/ApplicationInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/structure/ApplicationInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/structure/ApplicationInstance.java
index 0ca0b52..de6be04 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/structure/ApplicationInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/structure/ApplicationInstance.java
@@ -155,7 +155,7 @@ public class ApplicationInstance
     }
 
     // Other methods
-    /* package */ void addLayer( LayerInstance layer )
+    void addLayer( LayerInstance layer )
     {
         layer.registerActivationEventListener( activation );
         layerInstances.add( layer );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/runtime/src/main/java/org/apache/zest/runtime/structure/ApplicationModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/structure/ApplicationModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/structure/ApplicationModel.java
index fdcedfe..10e9f03 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/structure/ApplicationModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/structure/ApplicationModel.java
@@ -25,6 +25,7 @@ import org.apache.zest.api.common.InvalidApplicationException;
 import org.apache.zest.api.common.MetaInfo;
 import org.apache.zest.api.structure.Application;
 import org.apache.zest.api.structure.ApplicationDescriptor;
+import org.apache.zest.api.structure.LayerDescriptor;
 import org.apache.zest.bootstrap.ZestRuntime;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.runtime.activation.ActivatorsInstance;
@@ -124,31 +125,33 @@ public final class ApplicationModel
         ApplicationInstance applicationInstance = new ApplicationInstance( this, (ZestRuntime) runtime, instanceMetaInfo );
 
         // Create layer instances
-        Map<LayerModel, LayerInstance> layerInstanceMap = new HashMap<>();
-        Map<LayerModel, List<LayerInstance>> usedLayers = new HashMap<>();
+        Map<LayerDescriptor, LayerDescriptor> layerInstanceMap = new HashMap<>();
+        Map<LayerDescriptor, List<LayerDescriptor>> usedLayers = new HashMap<>();
         for( LayerModel layer : layers )
         {
-            List<LayerInstance> usedLayerInstances = new ArrayList<>();
+            List<LayerDescriptor> usedLayerInstances = new ArrayList<>();
             usedLayers.put( layer, usedLayerInstances );
             UsedLayersInstance usedLayersInstance = layer.usedLayers().newInstance( usedLayerInstances );
-            LayerInstance layerInstance = layer.newInstance( applicationInstance, usedLayersInstance );
+            LayerInstance layerInstance = layer.newInstance( applicationInstance );
             applicationInstance.addLayer( layerInstance );
-            layerInstanceMap.put( layer, layerInstance );
+            layerInstanceMap.put( layer, layerInstance.descriptor() );
         }
 
         // Resolve used layer instances
         for( LayerModel layer : layers )
         {
-            List<LayerInstance> usedLayerInstances = usedLayers.get( layer );
-            for( LayerModel usedLayer : layer.usedLayers().layers() )
-            {
-                LayerInstance layerInstance = layerInstanceMap.get( usedLayer );
-                if( layerInstance == null )
+            List<LayerDescriptor> usedLayerInstances = usedLayers.get( layer );
+            layer.usedLayers().layers().forEach(
+                usedLayer ->
                 {
-                    throw new InvalidApplicationException( "Could not find used layer:" + usedLayer.name() );
-                }
-                usedLayerInstances.add( layerInstance );
-            }
+                    LayerDescriptor layerDescriptor = layerInstanceMap.get( usedLayer );
+                    if( layerDescriptor == null )
+                    {
+                        throw new InvalidApplicationException( "Could not find used layer:" + usedLayer
+                            .name() );
+                    }
+                    usedLayerInstances.add( layerDescriptor );
+                } );
         }
 
         return applicationInstance;
@@ -162,12 +165,10 @@ public final class ApplicationModel
     @Override
     public String toString()
     {
-        final StringBuilder sb = new StringBuilder();
-        sb.append( "ApplicationModel" );
-        sb.append( "{name='" ).append( name ).append( '\'' );
-        sb.append( ", version='" ).append( version ).append( '\'' );
-        sb.append( ", mode=" ).append( mode );
-        sb.append( '}' );
-        return sb.toString();
+        return "ApplicationModel" +
+               "{name='" + name + '\'' +
+               ", version='" + version + '\'' +
+               ", mode=" + mode +
+               '}';
     }
 }


Mime
View raw message