polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [2/6] zest-qi4j git commit: Introduced ModuleSpi interface as an injectable entry point for primarily extensions. Reduced ModuleInstance use to ModuleSpi as much as possible. Provided a lot more information in EntityTypeNotFoundException, about which en
Date Thu, 25 Jun 2015 08:13:50 GMT
Introduced ModuleSpi interface as an injectable entry point for primarily extensions.
Reduced ModuleInstance use to ModuleSpi as much as possible.
 Provided a lot more information in EntityTypeNotFoundException, about which entities that are visible and from which module it was being accessed.


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/0b9b6555
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/0b9b6555
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/0b9b6555

Branch: refs/heads/develop
Commit: 0b9b6555558ff0fc90e221fa44fba0f2bdd3d0c9
Parents: 5e2b139
Author: Niclas Hedhman <niclas@hedhman.org>
Authored: Wed Jun 24 21:56:43 2015 +0800
Committer: Niclas Hedhman <niclas@hedhman.org>
Committed: Wed Jun 24 21:56:43 2015 +0800

----------------------------------------------------------------------
 .../java/org/qi4j/api/structure/Module.java     |   4 +
 .../unitofwork/EntityTypeNotFoundException.java |  28 +-
 .../java/org/qi4j/runtime/Qi4jRuntimeImpl.java  |  13 +-
 .../composite/AbstractModifierModel.java        |   6 +-
 .../runtime/composite/CompositeMethodModel.java |  10 +-
 .../composite/CompositeMethodsModel.java        |   4 +-
 .../qi4j/runtime/composite/CompositeModel.java  |   4 +-
 .../qi4j/runtime/composite/ConcernsModel.java   |   4 +-
 .../runtime/composite/SideEffectsModel.java     |   4 +-
 .../composite/TransientBuilderInstance.java     |   2 +-
 .../runtime/composite/TransientInstance.java    |  14 +-
 .../qi4j/runtime/composite/TransientModel.java  |   4 +-
 .../org/qi4j/runtime/entity/EntityInstance.java |   8 +-
 .../org/qi4j/runtime/entity/EntityModel.java    |   6 +-
 .../qi4j/runtime/injection/DependencyModel.java |  11 +-
 .../runtime/injection/InjectedFieldModel.java   |   4 +-
 .../runtime/injection/InjectionContext.java     |  11 +-
 .../StructureInjectionProviderFactory.java      |  12 +-
 .../provider/UsesInjectionProviderFactory.java  |   3 +-
 .../qi4j/runtime/structure/LayerInstance.java   |  42 ++-
 .../org/qi4j/runtime/structure/ModelModule.java | 107 ------
 .../qi4j/runtime/structure/ModuleInstance.java  |  83 ++++-
 .../runtime/structure/ModuleUnitOfWork.java     |  41 ++-
 .../org/qi4j/runtime/structure/TypeLookup.java  | 176 +++++-----
 .../runtime/structure/UsedLayersInstance.java   |  29 +-
 .../unitofwork/EntityBuilderInstance.java       |   2 +-
 .../runtime/unitofwork/UnitOfWorkInstance.java  |  12 +-
 .../runtime/value/ValueBuilderInstance.java     |   2 +-
 .../value/ValueBuilderWithPrototype.java        |   2 +-
 .../runtime/value/ValueBuilderWithState.java    |   2 +-
 .../org/qi4j/runtime/value/ValueInstance.java   |  18 +-
 .../java/org/qi4j/runtime/value/ValueModel.java |   4 +-
 .../qi4j/runtime/value/ValueStateInstance.java  |   2 +-
 .../spi/src/main/java/org/qi4j/spi/Qi4jSPI.java |   7 +
 .../helpers/JSONMapEntityStoreMixin.java        |  15 +-
 .../helpers/MapEntityStoreMixin.java            |  32 +-
 .../java/org/qi4j/spi/module/ModelModule.java   | 124 +++++++
 .../java/org/qi4j/spi/module/ModuleSpi.java     |  30 ++
 .../prefs/PreferencesEntityStoreMixin.java      |  26 +-
 .../entitystore/sql/SQLEntityStoreMixin.java    |  15 +-
 .../conversion/values/ValueToEntityMixin.java   | 335 ++++++++++---------
 .../org/qi4j/library/scheduler/Scheduler.java   |  15 +-
 42 files changed, 764 insertions(+), 509 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/api/src/main/java/org/qi4j/api/structure/Module.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/qi4j/api/structure/Module.java b/core/api/src/main/java/org/qi4j/api/structure/Module.java
index 7360f96..47ffab8 100644
--- a/core/api/src/main/java/org/qi4j/api/structure/Module.java
+++ b/core/api/src/main/java/org/qi4j/api/structure/Module.java
@@ -26,6 +26,9 @@ import org.qi4j.api.service.ServiceFinder;
 import org.qi4j.api.unitofwork.UnitOfWorkFactory;
 import org.qi4j.api.value.ValueBuilderFactory;
 import org.qi4j.api.value.ValueDescriptor;
+import org.qi4j.functional.Function;
+import org.qi4j.functional.Visitable;
+import org.qi4j.functional.Visitor;
 
 /**
  * API for interacting with a Module. Instances
@@ -76,4 +79,5 @@ public interface Module
      * @return the descriptor for a value composite or null if the class could not be found or the value composite is not visible
      */
     ValueDescriptor valueDescriptor( String typeName );
+
 }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/api/src/main/java/org/qi4j/api/unitofwork/EntityTypeNotFoundException.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/qi4j/api/unitofwork/EntityTypeNotFoundException.java b/core/api/src/main/java/org/qi4j/api/unitofwork/EntityTypeNotFoundException.java
index 311da62..5f51e65 100644
--- a/core/api/src/main/java/org/qi4j/api/unitofwork/EntityTypeNotFoundException.java
+++ b/core/api/src/main/java/org/qi4j/api/unitofwork/EntityTypeNotFoundException.java
@@ -15,6 +15,10 @@
  */
 package org.qi4j.api.unitofwork;
 
+import org.qi4j.functional.Function;
+
+import static org.qi4j.functional.Iterables.fold;
+
 /**
  * Qi4j exception to be thrown in case that an entity composite
  * was not found during a lookup call.
@@ -24,12 +28,32 @@ public class EntityTypeNotFoundException
 {
     private final String compositeType;
 
-    public EntityTypeNotFoundException( String entityType )
+    public EntityTypeNotFoundException( String entityType, String moduleName, Iterable<String> visibility )
     {
-        super("Could not find an EntityComposite of type " + entityType);
+        super( "Could not find an EntityComposite of type " + entityType + " in module [" + moduleName + "].\n" +
+               "\tThe following entity types are visible:\n" + join(visibility) );
         this.compositeType = entityType;
     }
 
+    private static String join( Iterable<String> visibility )
+    {
+        return fold( new Function<String, String>()
+        {
+            StringBuilder result;
+            {
+                result = new StringBuilder();
+            }
+
+            @Override
+            public String map( String type )
+            {
+                result.append( type );
+                result.append( "\n" );
+                return result.toString();
+            }
+        }, visibility );
+    }
+
     public String compositeType()
     {
         return compositeType;

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/Qi4jRuntimeImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/Qi4jRuntimeImpl.java b/core/runtime/src/main/java/org/qi4j/runtime/Qi4jRuntimeImpl.java
index 23ba27b..6869dae 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/Qi4jRuntimeImpl.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/Qi4jRuntimeImpl.java
@@ -15,7 +15,6 @@ package org.qi4j.runtime;
 
 import java.lang.reflect.InvocationHandler;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.Map;
 import org.qi4j.api.Qi4j;
 import org.qi4j.api.association.AbstractAssociation;
@@ -33,11 +32,10 @@ import org.qi4j.api.composite.CompositeInstance;
 import org.qi4j.api.composite.ModelDescriptor;
 import org.qi4j.api.composite.TransientComposite;
 import org.qi4j.api.composite.TransientDescriptor;
-import org.qi4j.api.entity.EntityBuilder;
 import org.qi4j.api.entity.EntityComposite;
 import org.qi4j.api.entity.EntityDescriptor;
 import org.qi4j.api.entity.EntityReference;
-import org.qi4j.api.entity.Identity;
+import org.qi4j.api.object.ObjectDescriptor;
 import org.qi4j.api.property.Property;
 import org.qi4j.api.property.PropertyDescriptor;
 import org.qi4j.api.property.PropertyWrapper;
@@ -46,35 +44,31 @@ import org.qi4j.api.service.ServiceComposite;
 import org.qi4j.api.service.ServiceDescriptor;
 import org.qi4j.api.service.ServiceReference;
 import org.qi4j.api.structure.Module;
-import org.qi4j.api.unitofwork.NoSuchEntityException;
 import org.qi4j.api.unitofwork.UnitOfWork;
-import org.qi4j.api.value.ValueBuilder;
 import org.qi4j.api.value.ValueComposite;
 import org.qi4j.api.value.ValueDescriptor;
 import org.qi4j.bootstrap.ApplicationAssemblyFactory;
 import org.qi4j.bootstrap.ApplicationModelFactory;
 import org.qi4j.bootstrap.Qi4jRuntime;
-import org.qi4j.functional.Function;
 import org.qi4j.runtime.association.AbstractAssociationInstance;
 import org.qi4j.runtime.association.AssociationInstance;
 import org.qi4j.runtime.association.ManyAssociationInstance;
 import org.qi4j.runtime.association.NamedAssociationInstance;
 import org.qi4j.runtime.bootstrap.ApplicationAssemblyFactoryImpl;
 import org.qi4j.runtime.bootstrap.ApplicationModelFactoryImpl;
-import org.qi4j.runtime.composite.FunctionStateResolver;
 import org.qi4j.runtime.composite.ProxyReferenceInvocationHandler;
 import org.qi4j.runtime.composite.TransientInstance;
 import org.qi4j.runtime.entity.EntityInstance;
-import org.qi4j.runtime.entity.EntityModel;
 import org.qi4j.runtime.property.PropertyInstance;
 import org.qi4j.runtime.service.ImportedServiceReferenceInstance;
 import org.qi4j.runtime.service.ServiceInstance;
 import org.qi4j.runtime.service.ServiceReferenceInstance;
+import org.qi4j.runtime.structure.ModuleInstance;
 import org.qi4j.runtime.structure.ModuleUnitOfWork;
 import org.qi4j.runtime.value.ValueInstance;
 import org.qi4j.spi.Qi4jSPI;
 import org.qi4j.spi.entity.EntityState;
-import org.qi4j.spi.entity.NamedAssociationState;
+import org.qi4j.spi.module.ModelModule;
 
 import static java.lang.reflect.Proxy.getInvocationHandler;
 import static org.qi4j.runtime.composite.TransientInstance.compositeInstanceOf;
@@ -364,5 +358,4 @@ public final class Qi4jRuntimeImpl
     {
         return ( (NamedAssociationInstance) assoc ).getEntityReferences();
     }
-
 }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/composite/AbstractModifierModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/AbstractModifierModel.java b/core/runtime/src/main/java/org/qi4j/runtime/composite/AbstractModifierModel.java
index 09499cb..b457f1d 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/AbstractModifierModel.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/AbstractModifierModel.java
@@ -25,7 +25,7 @@ import org.qi4j.runtime.injection.DependencyModel;
 import org.qi4j.runtime.injection.InjectedFieldsModel;
 import org.qi4j.runtime.injection.InjectedMethodsModel;
 import org.qi4j.runtime.injection.InjectionContext;
-import org.qi4j.runtime.structure.ModuleInstance;
+import org.qi4j.spi.module.ModuleSpi;
 
 import static org.qi4j.api.util.Classes.RAW_CLASS;
 import static org.qi4j.api.util.Classes.interfacesOf;
@@ -57,7 +57,7 @@ public abstract class AbstractModifierModel
         injectedFieldsModel = new InjectedFieldsModel( declaredModifierClass );
         injectedMethodsModel = new InjectedMethodsModel( declaredModifierClass );
         Class<Class<?>> componentType = (Class<Class<?>>) Class.class.cast( Class.class );
-        nextInterfaces = toArray( componentType, unique( map( RAW_CLASS, interfacesOf( declaredModifierClass ) ) ));
+        nextInterfaces = toArray( componentType, unique( map( RAW_CLASS, interfacesOf( declaredModifierClass ) ) ) );
     }
 
     public Class<?> modifierClass()
@@ -96,7 +96,7 @@ public abstract class AbstractModifierModel
     }
 
     // Context
-    public InvocationHandler newInstance( ModuleInstance moduleInstance,
+    public InvocationHandler newInstance( ModuleSpi moduleInstance,
                                           InvocationHandler next,
                                           ProxyReferenceInvocationHandler proxyHandler,
                                           Method method

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeMethodModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeMethodModel.java b/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeMethodModel.java
index e925b9d..3162130 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeMethodModel.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeMethodModel.java
@@ -29,7 +29,7 @@ import org.qi4j.functional.HierarchicalVisitor;
 import org.qi4j.functional.VisitableHierarchy;
 import org.qi4j.runtime.injection.Dependencies;
 import org.qi4j.runtime.injection.DependencyModel;
-import org.qi4j.runtime.structure.ModuleInstance;
+import org.qi4j.spi.module.ModuleSpi;
 
 import static org.qi4j.functional.Iterables.filter;
 import static org.qi4j.functional.Iterables.flattenIterables;
@@ -101,7 +101,7 @@ public final class CompositeMethodModel
     }
 
     // Context
-    public Object invoke( Object composite, Object[] params, MixinsInstance mixins, ModuleInstance moduleInstance )
+    public Object invoke( Object composite, Object[] params, MixinsInstance mixins, ModuleSpi moduleInstance )
         throws Throwable
     {
         constraintsInstance.checkValid( composite, method, params );
@@ -117,7 +117,7 @@ public final class CompositeMethodModel
         }
     }
 
-    private CompositeMethodInstance getInstance( ModuleInstance moduleInstance )
+    private CompositeMethodInstance getInstance( ModuleSpi moduleInstance )
     {
         CompositeMethodInstance methodInstance = instancePool.obtainInstance();
         if( methodInstance == null )
@@ -128,7 +128,7 @@ public final class CompositeMethodModel
         return methodInstance;
     }
 
-    private CompositeMethodInstance newCompositeMethodInstance( ModuleInstance moduleInstance )
+    private CompositeMethodInstance newCompositeMethodInstance( ModuleSpi moduleInstance )
         throws ConstructionException
     {
         FragmentInvocationHandler mixinInvocationHandler = mixins.newInvocationHandler( method );
@@ -197,7 +197,7 @@ public final class CompositeMethodModel
 
     public Iterable<Method> invocationsFor( Class<?> mixinClass )
     {
-        return mixins.invocationsFor(mixinClass);
+        return mixins.invocationsFor( mixinClass );
     }
 
     public class CompositeMethodAnnotatedElement

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeMethodsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeMethodsModel.java b/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeMethodsModel.java
index f18d222..bf0c113 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeMethodsModel.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeMethodsModel.java
@@ -22,7 +22,7 @@ import org.qi4j.functional.Iterables;
 import org.qi4j.functional.VisitableHierarchy;
 import org.qi4j.runtime.injection.Dependencies;
 import org.qi4j.runtime.injection.DependencyModel;
-import org.qi4j.runtime.structure.ModuleInstance;
+import org.qi4j.spi.module.ModuleSpi;
 
 import static org.qi4j.functional.Iterables.map;
 
@@ -51,7 +51,7 @@ public final class CompositeMethodsModel
                           Object proxy,
                           Method method,
                           Object[] args,
-                          ModuleInstance moduleInstance
+                          ModuleSpi moduleInstance
     )
         throws Throwable
     {

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeModel.java b/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeModel.java
index b7f0e6c..a6ea122 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeModel.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/CompositeModel.java
@@ -25,12 +25,14 @@ import org.qi4j.api.common.Visibility;
 import org.qi4j.api.composite.Composite;
 import org.qi4j.api.composite.CompositeDescriptor;
 import org.qi4j.api.composite.InvalidCompositeException;
+import org.qi4j.api.structure.Module;
 import org.qi4j.functional.HierarchicalVisitor;
 import org.qi4j.functional.Iterables;
 import org.qi4j.functional.VisitableHierarchy;
 import org.qi4j.runtime.injection.Dependencies;
 import org.qi4j.runtime.injection.DependencyModel;
 import org.qi4j.runtime.structure.ModuleInstance;
+import org.qi4j.spi.module.ModuleSpi;
 
 import static java.lang.reflect.Proxy.newProxyInstance;
 import static org.qi4j.functional.Iterables.first;
@@ -204,7 +206,7 @@ public abstract class CompositeModel
                                 Object proxy,
                                 Method method,
                                 Object[] args,
-                                ModuleInstance moduleInstance
+                                ModuleSpi moduleInstance
     )
         throws Throwable
     {

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/composite/ConcernsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/ConcernsModel.java b/core/runtime/src/main/java/org/qi4j/runtime/composite/ConcernsModel.java
index 9488c4b..74882f7 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/ConcernsModel.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/ConcernsModel.java
@@ -24,7 +24,7 @@ import org.qi4j.functional.Iterables;
 import org.qi4j.functional.VisitableHierarchy;
 import org.qi4j.runtime.injection.Dependencies;
 import org.qi4j.runtime.injection.DependencyModel;
-import org.qi4j.runtime.structure.ModuleInstance;
+import org.qi4j.spi.module.ModuleSpi;
 
 /**
  * JAVADOC
@@ -48,7 +48,7 @@ public final class ConcernsModel
     }
 
     // Context
-    public ConcernsInstance newInstance( Method method, ModuleInstance moduleInstance,
+    public ConcernsInstance newInstance( Method method, ModuleSpi moduleInstance,
                                          FragmentInvocationHandler mixinInvocationHandler
     )
     {

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/composite/SideEffectsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/SideEffectsModel.java b/core/runtime/src/main/java/org/qi4j/runtime/composite/SideEffectsModel.java
index 11018ff..10ae779 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/SideEffectsModel.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/SideEffectsModel.java
@@ -25,7 +25,7 @@ import org.qi4j.functional.Iterables;
 import org.qi4j.functional.VisitableHierarchy;
 import org.qi4j.runtime.injection.Dependencies;
 import org.qi4j.runtime.injection.DependencyModel;
-import org.qi4j.runtime.structure.ModuleInstance;
+import org.qi4j.spi.module.ModuleSpi;
 
 /**
  * JAVADOC
@@ -49,7 +49,7 @@ public final class SideEffectsModel
     }
 
     // Context
-    public SideEffectsInstance newInstance( Method method, ModuleInstance moduleInstance, InvocationHandler invoker )
+    public SideEffectsInstance newInstance( Method method, ModuleSpi moduleInstance, InvocationHandler invoker )
     {
         ProxyReferenceInvocationHandler proxyHandler = new ProxyReferenceInvocationHandler();
         SideEffectInvocationHandlerResult result = new SideEffectInvocationHandlerResult();

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientBuilderInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientBuilderInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientBuilderInstance.java
index 0bb343f..ffb3fc6 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientBuilderInstance.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientBuilderInstance.java
@@ -20,7 +20,7 @@ import org.qi4j.api.composite.TransientBuilder;
 import org.qi4j.api.property.PropertyDescriptor;
 import org.qi4j.runtime.property.PropertyInfo;
 import org.qi4j.runtime.property.PropertyInstance;
-import org.qi4j.runtime.structure.ModelModule;
+import org.qi4j.spi.module.ModelModule;
 
 /**
  * JAVADOC

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientInstance.java
index 811fce7..78bc5a2 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientInstance.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientInstance.java
@@ -24,7 +24,10 @@ import org.qi4j.api.Qi4j;
 import org.qi4j.api.composite.Composite;
 import org.qi4j.api.composite.CompositeInstance;
 import org.qi4j.api.property.StateHolder;
+import org.qi4j.api.structure.Layer;
+import org.qi4j.api.structure.Module;
 import org.qi4j.runtime.structure.ModuleInstance;
+import org.qi4j.spi.module.ModuleSpi;
 
 /**
  * InvocationHandler for proxy objects.
@@ -42,10 +45,10 @@ public class TransientInstance
     protected final Object[] mixins;
     protected StateHolder state;
     protected final CompositeModel compositeModel;
-    private final ModuleInstance moduleInstance;
+    private final ModuleSpi moduleInstance;
 
     public TransientInstance( CompositeModel compositeModel,
-                              ModuleInstance moduleInstance,
+                              ModuleSpi moduleInstance,
                               Object[] mixins,
                               StateHolder state
     )
@@ -105,11 +108,16 @@ public class TransientInstance
     }
 
     @Override
-    public ModuleInstance module()
+    public Module module()
     {
         return moduleInstance;
     }
 
+    public Layer layer()
+    {
+        return ( (ModuleInstance) moduleInstance ).layerInstance();
+    }
+
     @Override
     public StateHolder state()
     {

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientModel.java b/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientModel.java
index c5ffe79..968fa5e 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientModel.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/composite/TransientModel.java
@@ -20,7 +20,7 @@ import org.qi4j.api.composite.TransientDescriptor;
 import org.qi4j.api.constraint.ConstraintViolationException;
 import org.qi4j.runtime.injection.InjectionContext;
 import org.qi4j.runtime.property.PropertyModel;
-import org.qi4j.runtime.structure.ModuleInstance;
+import org.qi4j.spi.module.ModuleSpi;
 
 /**
  * Model for Transient Composites
@@ -39,7 +39,7 @@ public class TransientModel
         super( types, visibility, metaInfo, mixinsModel, stateModel, compositeMethodsModel );
     }
 
-    public TransientInstance newInstance( ModuleInstance moduleInstance,
+    public TransientInstance newInstance( ModuleSpi moduleInstance,
                                           UsesInstance uses,
                                           TransientStateInstance state
     )

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityInstance.java
index 6e7e513..86affb7 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityInstance.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityInstance.java
@@ -31,6 +31,7 @@ import org.qi4j.api.entity.EntityComposite;
 import org.qi4j.api.entity.EntityReference;
 import org.qi4j.api.entity.Identity;
 import org.qi4j.api.entity.LifecycleException;
+import org.qi4j.api.structure.Module;
 import org.qi4j.api.unitofwork.NoSuchEntityException;
 import org.qi4j.api.unitofwork.UnitOfWork;
 import org.qi4j.api.unitofwork.UnitOfWorkException;
@@ -40,6 +41,7 @@ import org.qi4j.runtime.structure.ModuleInstance;
 import org.qi4j.runtime.structure.ModuleUnitOfWork;
 import org.qi4j.spi.entity.EntityState;
 import org.qi4j.spi.entity.EntityStatus;
+import org.qi4j.spi.module.ModuleSpi;
 
 /**
  * Entity instance
@@ -54,7 +56,7 @@ public final class EntityInstance
 
     private final EntityComposite proxy;
     private final ModuleUnitOfWork uow;
-    private final ModuleInstance moduleInstance;
+    private final ModuleSpi moduleInstance;
     private final EntityModel entityModel;
     private final EntityReference identity;
     private final EntityState entityState;
@@ -63,7 +65,7 @@ public final class EntityInstance
     private EntityStateInstance state;
 
     public EntityInstance( ModuleUnitOfWork uow,
-                           ModuleInstance moduleInstance,
+                           ModuleSpi moduleInstance,
                            EntityModel entityModel,
                            EntityState entityState
     )
@@ -134,7 +136,7 @@ public final class EntityInstance
     }
 
     @Override
-    public ModuleInstance module()
+    public ModuleSpi module()
     {
         return moduleInstance;
     }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityModel.java b/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityModel.java
index 77103f9..3563115 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityModel.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityModel.java
@@ -33,12 +33,12 @@ import org.qi4j.functional.Iterables;
 import org.qi4j.runtime.composite.CompositeMethodsModel;
 import org.qi4j.runtime.composite.CompositeModel;
 import org.qi4j.runtime.property.PropertyModel;
-import org.qi4j.runtime.structure.ModuleInstance;
 import org.qi4j.runtime.structure.ModuleUnitOfWork;
 import org.qi4j.spi.entity.EntityState;
 import org.qi4j.spi.entitystore.EntityAlreadyExistsException;
 import org.qi4j.spi.entitystore.EntityStoreException;
 import org.qi4j.spi.entitystore.EntityStoreUnitOfWork;
+import org.qi4j.spi.module.ModuleSpi;
 
 import static org.qi4j.functional.Iterables.filter;
 import static org.qi4j.functional.Iterables.first;
@@ -96,7 +96,7 @@ public final class EntityModel
         return (EntityStateModel) super.state();
     }
 
-    public EntityInstance newInstance( ModuleUnitOfWork uow, ModuleInstance moduleInstance, EntityState state )
+    public EntityInstance newInstance( ModuleUnitOfWork uow, ModuleSpi moduleInstance, EntityState state )
     {
         EntityInstance instance = new EntityInstance( uow, moduleInstance, this, state );
         return instance;
@@ -140,7 +140,7 @@ public final class EntityModel
         }
     }
 
-    public void initState( ModuleInstance module, EntityState entityState )
+    public void initState( ModuleSpi module, EntityState entityState )
     {
         // Set new properties to default value
         for( PropertyModel propertyDescriptor : state().properties() )

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/injection/DependencyModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/injection/DependencyModel.java b/core/runtime/src/main/java/org/qi4j/runtime/injection/DependencyModel.java
index bfc5317..b01f799 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/injection/DependencyModel.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/injection/DependencyModel.java
@@ -287,16 +287,15 @@ public final class DependencyModel
                 ex = ex.getCause();
             }
 
-            String message = "[Module " + context.module()
-                .name() + "] InjectionProvider unable to resolve @" + injectionAnnotation.annotationType()
-                .getSimpleName() + " " + injectionType.toString();
+            String message = "[Module " + context.module().name() + "] InjectionProvider unable to resolve @" +
+                             injectionAnnotation.annotationType().getSimpleName() + " " + injectionType.toString();
             throw new ConstructionException( message, ex );
         }
         if( injectedValue == null && !optional )
         {
-            String message = "[Module " + context.module()
-                .name() + "] Non-optional @" + injectionAnnotation.annotationType()
-                .getSimpleName() + " " + injectionType.toString() + " was null in " + injectedClass.getName();
+            String message = "[Module " + context.module().name() + "] Non-optional @" +
+                             injectionAnnotation.annotationType().getSimpleName() + " " + injectionType.toString() +
+                             " was null in " + injectedClass.getName();
             throw new ConstructionException( message );
         }
         return getInjectedValue( injectedValue );

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/injection/InjectedFieldModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/injection/InjectedFieldModel.java b/core/runtime/src/main/java/org/qi4j/runtime/injection/InjectedFieldModel.java
index 6b35f2a..bd51924 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/injection/InjectedFieldModel.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/injection/InjectedFieldModel.java
@@ -87,9 +87,7 @@ public final class InjectedFieldModel
                 {
                     TransientInstance handler = (TransientInstance) invocationHandler;
                     valueClassName = Classes.toString( handler.descriptor().types() )
-                                     + " in [" + handler.module().name() + "] of [" + handler.module()
-                        .layerInstance()
-                        .name() + "]";
+                                     + " in [" + handler.module().name() + "] of [" + handler.layer().name() + "]";
                 }
                 else
                 {

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/injection/InjectionContext.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/injection/InjectionContext.java b/core/runtime/src/main/java/org/qi4j/runtime/injection/InjectionContext.java
index f9c1deb..b3c4981 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/injection/InjectionContext.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/injection/InjectionContext.java
@@ -19,13 +19,14 @@ import org.qi4j.api.property.StateHolder;
 import org.qi4j.runtime.composite.ProxyReferenceInvocationHandler;
 import org.qi4j.runtime.composite.UsesInstance;
 import org.qi4j.runtime.structure.ModuleInstance;
+import org.qi4j.spi.module.ModuleSpi;
 
 /**
  * JAVADOC
  */
 public final class InjectionContext
 {
-    private final ModuleInstance moduleInstance;
+    private final ModuleSpi moduleInstance;
     private CompositeInstance compositeInstance;
     private UsesInstance uses;
     private StateHolder state;
@@ -44,28 +45,28 @@ public final class InjectionContext
     }
 
     // For concerns and side-effects
-    public InjectionContext( ModuleInstance moduleInstance, Object next, ProxyReferenceInvocationHandler proxyHandler )
+    public InjectionContext( ModuleSpi moduleInstance, Object next, ProxyReferenceInvocationHandler proxyHandler )
     {
         this.moduleInstance = moduleInstance;
         this.next = next;
         this.proxyHandler = proxyHandler;
     }
 
-    public InjectionContext( ModuleInstance moduleInstance, UsesInstance uses )
+    public InjectionContext( ModuleSpi moduleInstance, UsesInstance uses )
     {
         this.moduleInstance = moduleInstance;
         this.uses = uses;
     }
 
     // For inner classes
-    public InjectionContext( ModuleInstance moduleInstance, UsesInstance uses, Object instance )
+    public InjectionContext( ModuleSpi moduleInstance, UsesInstance uses, Object instance )
     {
         this.moduleInstance = moduleInstance;
         this.uses = uses;
         this.instance = instance;
     }
 
-    public ModuleInstance module()
+    public ModuleSpi module()
     {
         return moduleInstance;
     }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/injection/provider/StructureInjectionProviderFactory.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/injection/provider/StructureInjectionProviderFactory.java b/core/runtime/src/main/java/org/qi4j/runtime/injection/provider/StructureInjectionProviderFactory.java
index dd461e6..6ad4e30 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/injection/provider/StructureInjectionProviderFactory.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/injection/provider/StructureInjectionProviderFactory.java
@@ -34,6 +34,8 @@ import org.qi4j.runtime.injection.InjectionContext;
 import org.qi4j.runtime.injection.InjectionProvider;
 import org.qi4j.runtime.injection.InjectionProviderFactory;
 import org.qi4j.runtime.model.Resolution;
+import org.qi4j.runtime.structure.ModuleInstance;
+import org.qi4j.spi.module.ModuleSpi;
 
 public final class StructureInjectionProviderFactory
     implements InjectionProviderFactory
@@ -93,17 +95,21 @@ public final class StructureInjectionProviderFactory
             {
                 return context.module();
             }
+            else if( ModuleSpi.class.isAssignableFrom( clazz ) )
+            {
+                return context.module();
+            }
             else if( Layer.class.isAssignableFrom( clazz ) )
             {
-                return context.module().layerInstance();
+                return (( ModuleInstance) context.module()).layerInstance();
             }
             else if( Application.class.isAssignableFrom( clazz ) )
             {
-                return context.module().layerInstance().applicationInstance();
+                return (( ModuleInstance) context.module()).layerInstance().applicationInstance();
             }
             else if( Qi4j.class.isAssignableFrom( clazz ) )
             {
-                return context.module().layerInstance().applicationInstance().runtime();
+                return (( ModuleInstance) context.module()).layerInstance().applicationInstance().runtime();
             }
 
             return null;

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/injection/provider/UsesInjectionProviderFactory.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/injection/provider/UsesInjectionProviderFactory.java b/core/runtime/src/main/java/org/qi4j/runtime/injection/provider/UsesInjectionProviderFactory.java
index c0e5f3d..2069d07 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/injection/provider/UsesInjectionProviderFactory.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/injection/provider/UsesInjectionProviderFactory.java
@@ -21,6 +21,7 @@ package org.qi4j.runtime.injection.provider;
 import java.lang.reflect.Constructor;
 import org.qi4j.api.composite.NoSuchTransientException;
 import org.qi4j.api.object.NoSuchObjectException;
+import org.qi4j.api.structure.Module;
 import org.qi4j.bootstrap.InvalidInjectionException;
 import org.qi4j.runtime.composite.UsesInstance;
 import org.qi4j.runtime.injection.DependencyModel;
@@ -71,7 +72,7 @@ public final class UsesInjectionProviderFactory
             {
                 // No @Uses object provided
                 // Try instantiating a Transient or Object for the given type
-                ModuleInstance moduleInstance = context.module();
+                Module moduleInstance = context.module();
 
                 try
                 {

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/structure/LayerInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/structure/LayerInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/structure/LayerInstance.java
index 9ed77bb..9e678e8 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/structure/LayerInstance.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/structure/LayerInstance.java
@@ -20,14 +20,15 @@ import org.qi4j.api.activation.ActivationEventListener;
 import org.qi4j.api.activation.ActivationException;
 import org.qi4j.api.activation.PassivationException;
 import org.qi4j.api.common.Visibility;
+import org.qi4j.api.composite.TransientDescriptor;
+import org.qi4j.api.entity.EntityDescriptor;
+import org.qi4j.api.object.ObjectDescriptor;
 import org.qi4j.api.service.ServiceReference;
 import org.qi4j.api.structure.Layer;
+import org.qi4j.api.value.ValueDescriptor;
 import org.qi4j.functional.Function;
 import org.qi4j.runtime.activation.ActivationDelegate;
-import org.qi4j.runtime.composite.TransientModel;
-import org.qi4j.runtime.entity.EntityModel;
-import org.qi4j.runtime.object.ObjectModel;
-import org.qi4j.runtime.value.ValueModel;
+import org.qi4j.spi.module.ModelModule;
 
 import static org.qi4j.functional.Iterables.flattenIterables;
 import static org.qi4j.functional.Iterables.map;
@@ -49,7 +50,8 @@ public class LayerInstance
 
     public LayerInstance( LayerModel model,
                           ApplicationInstance applicationInstance,
-                          UsedLayersInstance usedLayersInstance )
+                          UsedLayersInstance usedLayersInstance
+    )
     {
         // Constructor parameters
         this.layerModel = model;
@@ -130,59 +132,55 @@ public class LayerInstance
         return usedLayersInstance;
     }
 
-    /* package */ Iterable<ModelModule<ObjectModel>> visibleObjects( final Visibility visibility )
+    /* package */ Iterable<ModelModule<ObjectDescriptor>> visibleObjects( final Visibility visibility )
     {
-        return flattenIterables( map( new Function<ModuleInstance, Iterable<ModelModule<ObjectModel>>>()
+        return flattenIterables( map( new Function<ModuleInstance, Iterable<ModelModule<ObjectDescriptor>>>()
         {
 
             @Override
-            public Iterable<ModelModule<ObjectModel>> map( ModuleInstance moduleInstance )
+            public Iterable<ModelModule<ObjectDescriptor>> map( ModuleInstance moduleInstance )
             {
                 return moduleInstance.visibleObjects( visibility );
             }
-
         }, moduleInstances ) );
     }
 
-    /* package */ Iterable<ModelModule<TransientModel>> visibleTransients( final Visibility visibility )
+    /* package */ Iterable<ModelModule<TransientDescriptor>> visibleTransients( final Visibility visibility )
     {
-        return flattenIterables( map( new Function<ModuleInstance, Iterable<ModelModule<TransientModel>>>()
+        return flattenIterables( map( new Function<ModuleInstance, Iterable<ModelModule<TransientDescriptor>>>()
         {
 
             @Override
-            public Iterable<ModelModule<TransientModel>> map( ModuleInstance moduleInstance )
+            public Iterable<ModelModule<TransientDescriptor>> map( ModuleInstance moduleInstance )
             {
                 return moduleInstance.visibleTransients( visibility );
             }
-
         }, moduleInstances ) );
     }
 
-    /* package */ Iterable<ModelModule<EntityModel>> visibleEntities( final Visibility visibility )
+    /* package */ Iterable<ModelModule<EntityDescriptor>> visibleEntities( final Visibility visibility )
     {
-        return flattenIterables( map( new Function<ModuleInstance, Iterable<ModelModule<EntityModel>>>()
+        return flattenIterables( map( new Function<ModuleInstance, Iterable<ModelModule<EntityDescriptor>>>()
         {
 
             @Override
-            public Iterable<ModelModule<EntityModel>> map( ModuleInstance moduleInstance )
+            public Iterable<ModelModule<EntityDescriptor>> map( ModuleInstance moduleInstance )
             {
                 return moduleInstance.visibleEntities( visibility );
             }
-
         }, moduleInstances ) );
     }
 
-    /* package */ Iterable<ModelModule<ValueModel>> visibleValues( final Visibility visibility )
+    /* package */ Iterable<ModelModule<ValueDescriptor>> visibleValues( final Visibility visibility )
     {
-        return flattenIterables( map( new Function<ModuleInstance, Iterable<ModelModule<ValueModel>>>()
+        return flattenIterables( map( new Function<ModuleInstance, Iterable<ModelModule<ValueDescriptor>>>()
         {
 
             @Override
-            public Iterable<ModelModule<ValueModel>> map( ModuleInstance moduleInstance )
+            public Iterable<ModelModule<ValueDescriptor>> map( ModuleInstance moduleInstance )
             {
                 return moduleInstance.visibleValues( visibility );
             }
-
         }, moduleInstances ) );
     }
 
@@ -196,7 +194,6 @@ public class LayerInstance
             {
                 return moduleInstance.visibleServices( visibility );
             }
-
         }, moduleInstances ) );
     }
 
@@ -212,5 +209,4 @@ public class LayerInstance
 
         throw new IllegalArgumentException( "No such module:" + moduleName );
     }
-
 }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/structure/ModelModule.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/structure/ModelModule.java b/core/runtime/src/main/java/org/qi4j/runtime/structure/ModelModule.java
deleted file mode 100644
index dae30b9..0000000
--- a/core/runtime/src/main/java/org/qi4j/runtime/structure/ModelModule.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.qi4j.runtime.structure;
-
-import org.qi4j.api.composite.ModelDescriptor;
-import org.qi4j.functional.Function;
-
-/**
- * TODO
- */
-public class ModelModule<T extends ModelDescriptor>
-{
-    public static <T extends ModelDescriptor> Function<T, ModelModule<T>> modelModuleFunction( final ModuleInstance module )
-    {
-        return new Function<T, ModelModule<T>>()
-        {
-            @Override
-            public ModelModule<T> map( T model )
-            {
-                return new ModelModule<>( module, model );
-            }
-        };
-    }
-
-    public static <T extends ModelDescriptor> Function<ModelModule<T>, T> modelFunction()
-    {
-        return new Function<ModelModule<T>, T>()
-        {
-            @Override
-            public T map( ModelModule<T> modelModule )
-            {
-                return modelModule.model();
-            }
-        };
-    }
-
-    private final ModuleInstance module;
-    private final T model;
-
-    public ModelModule( ModuleInstance module, T model )
-    {
-        this.module = module;
-        this.model = model;
-    }
-
-    public ModuleInstance module()
-    {
-        return module;
-    }
-
-    public T model()
-    {
-        return model;
-    }
-
-    @Override
-    public boolean equals( Object o )
-    {
-        if( this == o )
-        {
-            return true;
-        }
-        if( o == null || getClass() != o.getClass() )
-        {
-            return false;
-        }
-
-        ModelModule that = (ModelModule) o;
-
-        if( model != null ? !model.equals( that.model ) : that.model != null )
-        {
-            return false;
-        }
-
-        return !( module != null ? !module.equals( that.module ) : that.module != null );
-    }
-
-    @Override
-    public int hashCode()
-    {
-        int result = module != null ? module.hashCode() : 0;
-        result = 31 * result + ( model != null ? model.hashCode() : 0 );
-        return result;
-    }
-
-    @Override
-    public String toString()
-    {
-        return module.name() + ":" + model;
-    }
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleInstance.java
index c009c75..97addf3 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleInstance.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleInstance.java
@@ -50,6 +50,7 @@ import org.qi4j.api.property.PropertyDescriptor;
 import org.qi4j.api.query.QueryBuilder;
 import org.qi4j.api.query.QueryBuilderFactory;
 import org.qi4j.api.service.NoSuchServiceException;
+import org.qi4j.api.service.ServiceDescriptor;
 import org.qi4j.api.service.ServiceReference;
 import org.qi4j.api.structure.Module;
 import org.qi4j.api.unitofwork.UnitOfWork;
@@ -69,6 +70,7 @@ import org.qi4j.functional.Specification;
 import org.qi4j.functional.Specifications;
 import org.qi4j.runtime.activation.ActivationDelegate;
 import org.qi4j.runtime.composite.FunctionStateResolver;
+import org.qi4j.runtime.composite.StateResolver;
 import org.qi4j.runtime.composite.TransientBuilderInstance;
 import org.qi4j.runtime.composite.TransientModel;
 import org.qi4j.runtime.composite.TransientStateInstance;
@@ -88,7 +90,6 @@ import org.qi4j.runtime.service.ImportedServicesModel;
 import org.qi4j.runtime.service.ServicesInstance;
 import org.qi4j.runtime.service.ServicesModel;
 import org.qi4j.runtime.unitofwork.UnitOfWorkInstance;
-import org.qi4j.runtime.composite.StateResolver;
 import org.qi4j.runtime.value.ValueBuilderInstance;
 import org.qi4j.runtime.value.ValueBuilderWithPrototype;
 import org.qi4j.runtime.value.ValueBuilderWithState;
@@ -97,8 +98,13 @@ import org.qi4j.runtime.value.ValueModel;
 import org.qi4j.runtime.value.ValuesModel;
 import org.qi4j.spi.entitystore.EntityStore;
 import org.qi4j.spi.metrics.MetricsProviderAdapter;
+import org.qi4j.spi.module.ModelModule;
+import org.qi4j.spi.module.ModuleSpi;
 import org.qi4j.valueserialization.orgjson.OrgJsonValueSerialization;
 
+import static org.qi4j.api.common.Visibility.application;
+import static org.qi4j.api.common.Visibility.layer;
+import static org.qi4j.api.common.Visibility.module;
 import static org.qi4j.api.util.Classes.RAW_CLASS;
 import static org.qi4j.api.util.Classes.modelTypeSpecification;
 import static org.qi4j.functional.Iterables.cast;
@@ -113,7 +119,7 @@ import static org.qi4j.functional.Iterables.toList;
  * Instance of a Qi4j Module. Contains the various composites for this Module.
  */
 public class ModuleInstance
-    implements Module, Activation
+    implements Module, ModuleSpi, Activation
 {
     // Constructor parameters
     private final ModuleModel model;
@@ -139,7 +145,8 @@ public class ModuleInstance
     @SuppressWarnings( "LeakingThisInConstructor" )
     public ModuleInstance( ModuleModel moduleModel, LayerInstance layerInstance, TransientsModel transientsModel,
                            EntitiesModel entitiesModel, ObjectsModel objectsModel, ValuesModel valuesModel,
-                           ServicesModel servicesModel, ImportedServicesModel importedServicesModel )
+                           ServicesModel servicesModel, ImportedServicesModel importedServicesModel
+    )
     {
         // Constructor parameters
         model = moduleModel;
@@ -360,7 +367,8 @@ public class ModuleInstance
                                                          Function<PropertyDescriptor, Object> propertyFunction,
                                                          Function<AssociationDescriptor, EntityReference> associationFunction,
                                                          Function<AssociationDescriptor, Iterable<EntityReference>> manyAssociationFunction,
-                                                         Function<AssociationDescriptor, Map<String, EntityReference>> namedAssociationFunction )
+                                                         Function<AssociationDescriptor, Map<String, EntityReference>> namedAssociationFunction
+    )
     {
         NullArgumentException.validateNotNull( "propertyFunction", propertyFunction );
         NullArgumentException.validateNotNull( "associationFunction", associationFunction );
@@ -383,9 +391,9 @@ public class ModuleInstance
     private static class InitialStateResolver
         implements StateResolver
     {
-        private final ModuleInstance module;
+        private final Module module;
 
-        private InitialStateResolver( ModuleInstance module )
+        private InitialStateResolver( Module module )
         {
             this.module = module;
         }
@@ -567,7 +575,6 @@ public class ModuleInstance
         activation.deregisterActivationEventListener( listener );
     }
 
-
     // Other methods
     /* package */ ModuleModel model()
     {
@@ -624,7 +631,7 @@ public class ModuleInstance
         return store;
     }
 
-    /* package */ IdentityGenerator identityGenerator()
+    public IdentityGenerator identityGenerator()
     {
         synchronized( this )
         {
@@ -677,31 +684,31 @@ public class ModuleInstance
         return metrics;
     }
 
-    Iterable<ModelModule<ObjectModel>> visibleObjects( Visibility visibility )
+    public Iterable<ModelModule<ObjectDescriptor>> visibleObjects( Visibility visibility )
     {
-        return map( ModelModule.<ObjectModel>modelModuleFunction( this ),
+        return map( ModelModule.<ObjectDescriptor>modelModuleFunction( this ),
                     filter( new VisibilitySpecification( visibility ), objects.models() ) );
     }
 
-    Iterable<ModelModule<TransientModel>> visibleTransients( Visibility visibility )
+    public Iterable<ModelModule<TransientDescriptor>> visibleTransients( Visibility visibility )
     {
-        return map( ModelModule.<TransientModel>modelModuleFunction( this ),
+        return map( ModelModule.<TransientDescriptor>modelModuleFunction( this ),
                     filter( new VisibilitySpecification( visibility ), transients.models() ) );
     }
 
-    Iterable<ModelModule<EntityModel>> visibleEntities( Visibility visibility )
+    public Iterable<ModelModule<EntityDescriptor>> visibleEntities( Visibility visibility )
     {
-        return map( ModelModule.<EntityModel>modelModuleFunction( this ),
+        return map( ModelModule.<EntityDescriptor>modelModuleFunction( this ),
                     filter( new VisibilitySpecification( visibility ), entities.models() ) );
     }
 
-    Iterable<ModelModule<ValueModel>> visibleValues( Visibility visibility )
+    public Iterable<ModelModule<ValueDescriptor>> visibleValues( Visibility visibility )
     {
-        return map( ModelModule.<ValueModel>modelModuleFunction( this ),
+        return map( ModelModule.<ValueDescriptor>modelModuleFunction( this ),
                     filter( new VisibilitySpecification( visibility ), values.models() ) );
     }
 
-    Iterable<ServiceReference<?>> visibleServices( Visibility visibility )
+    public Iterable<ServiceReference<?>> visibleServices( Visibility visibility )
     {
         return flatten( services.visibleServices( visibility ),
                         importedServices.visibleServices( visibility ) );
@@ -824,4 +831,46 @@ public class ModuleInstance
             return clazz;
         }
     }
+
+    public Iterable<ModelModule<ValueDescriptor>> findVisibleValueTypes()
+    {
+        return flatten( visibleValues( Visibility.module ),
+            layerInstance().visibleValues( Visibility.layer ),
+            layerInstance().visibleValues( Visibility.application ),
+            layerInstance().usedLayersInstance().visibleValues()
+        );
+    }
+
+    public Iterable<ModelModule<EntityDescriptor>> findVisibleEntityTypes()
+    {
+        return flatten( visibleEntities( Visibility.module ),
+            layerInstance().visibleEntities( Visibility.layer ),
+            layerInstance().visibleEntities( Visibility.application ),
+            layerInstance().usedLayersInstance().visibleEntities()
+        );
+    }
+    public Iterable<ModelModule<TransientDescriptor>> findVisibleTransientTypes()
+    {
+        return flatten( visibleTransients( Visibility.module ),
+            layerInstance().visibleTransients( Visibility.layer ),
+            layerInstance().visibleTransients( Visibility.application ),
+            layerInstance().usedLayersInstance().visibleTransients()
+        );
+    }
+    public Iterable<ModelModule<ServiceDescriptor>> findVisibleServiceTypes()
+    {
+        return flatten( visibleServices( Visibility.module ),
+            layerInstance().visibleServices( Visibility.layer ),
+            layerInstance().visibleServices( Visibility.application ),
+            layerInstance().usedLayersInstance().visibleServices()
+        );
+    }
+    public Iterable<ModelModule<ObjectDescriptor>> findVisibleObjectTypes()
+    {
+        return flatten( visibleObjects( Visibility.module ),
+            layerInstance().visibleObjects( Visibility.layer ),
+            layerInstance().visibleObjects( Visibility.application ),
+            layerInstance().usedLayersInstance().visibleObjects()
+        );
+    }
 }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleUnitOfWork.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleUnitOfWork.java b/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleUnitOfWork.java
index a4b6b06..77aebc5 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleUnitOfWork.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleUnitOfWork.java
@@ -61,10 +61,12 @@ import org.qi4j.runtime.property.PropertyModel;
 import org.qi4j.runtime.unitofwork.EntityBuilderInstance;
 import org.qi4j.runtime.unitofwork.UnitOfWorkInstance;
 import org.qi4j.runtime.value.ValueInstance;
+import org.qi4j.spi.Qi4jSPI;
 import org.qi4j.spi.entity.EntityState;
 import org.qi4j.spi.entity.EntityStatus;
 import org.qi4j.spi.entity.NamedAssociationState;
 import org.qi4j.spi.entitystore.EntityStore;
+import org.qi4j.spi.module.ModelModule;
 import org.qi4j.spi.query.EntityFinder;
 import org.qi4j.spi.query.EntityFinderException;
 import org.qi4j.spi.query.QueryBuilderSPI;
@@ -72,6 +74,7 @@ import org.qi4j.spi.query.QuerySource;
 
 import static org.qi4j.api.entity.EntityReference.parseEntityReference;
 import static org.qi4j.functional.Iterables.first;
+import static org.qi4j.functional.Iterables.map;
 
 /**
  * JAVADOC
@@ -94,17 +97,17 @@ public class ModuleUnitOfWork
     }
 
     private final UnitOfWorkInstance uow;
-    private final ModuleInstance moduleInstance;
+    private final ModuleInstance module;
 
-    ModuleUnitOfWork( ModuleInstance moduleInstance, UnitOfWorkInstance uow )
+    ModuleUnitOfWork( ModuleInstance module, UnitOfWorkInstance uow )
     {
-        this.moduleInstance = moduleInstance;
+        this.module = module;
         this.uow = uow;
     }
 
     public ModuleInstance module()
     {
-        return moduleInstance;
+        return module;
     }
 
     public UnitOfWorkInstance instance()
@@ -115,7 +118,7 @@ public class ModuleUnitOfWork
     @Override
     public UnitOfWorkFactory unitOfWorkFactory()
     {
-        return moduleInstance;
+        return module;
     }
 
     @Override
@@ -176,11 +179,15 @@ public class ModuleUnitOfWork
     public <T> EntityBuilder<T> newEntityBuilder( Class<T> type, String identity )
         throws EntityTypeNotFoundException
     {
-        ModelModule<EntityModel> model = moduleInstance.typeLookup().lookupEntityModel( type );
+        ModelModule<EntityModel> model = module.typeLookup().lookupEntityModel( type );
 
         if( model == null )
         {
-            throw new EntityTypeNotFoundException( type.getName() );
+            throw new EntityTypeNotFoundException( type.getName(),
+                                                   module.name(),
+                                                   map( ModelModule.toStringFunction,
+                                                        module.findVisibleEntityTypes()
+                                                   ) );
         }
 
         EntityStore entityStore = model.module().entityStore();
@@ -199,7 +206,7 @@ public class ModuleUnitOfWork
 
         builder = new EntityBuilderInstance<>( model,
                                                this,
-                                               uow.getEntityStoreUnitOfWork( entityStore, moduleInstance ),
+                                               uow.getEntityStoreUnitOfWork( entityStore, module ),
                                                identity );
         return builder;
     }
@@ -236,11 +243,15 @@ public class ModuleUnitOfWork
         NullArgumentException.validateNotNull( "manyAssociationFunction", manyAssociationFunction );
         NullArgumentException.validateNotNull( "namedAssociationFunction", namedAssociationFunction );
 
-        ModelModule<EntityModel> model = moduleInstance.typeLookup().lookupEntityModel( type );
+        ModelModule<EntityModel> model = module.typeLookup().lookupEntityModel( type );
 
         if( model == null )
         {
-            throw new EntityTypeNotFoundException( type.getName() );
+            throw new EntityTypeNotFoundException( type.getName(),
+                                                   module.name(),
+                                                   map( ModelModule.toStringFunction,
+                                                        module.findVisibleEntityTypes()
+                                                   ) );
         }
 
         EntityStore entityStore = model.module().entityStore();
@@ -268,7 +279,7 @@ public class ModuleUnitOfWork
 
         return new EntityBuilderInstance<>( model,
                                             this,
-                                            uow.getEntityStoreUnitOfWork( entityStore, moduleInstance ),
+                                            uow.getEntityStoreUnitOfWork( entityStore, module ),
                                             identity,
                                             stateResolver );
     }
@@ -277,11 +288,15 @@ public class ModuleUnitOfWork
     public <T> T get( Class<T> type, String identity )
         throws EntityTypeNotFoundException, NoSuchEntityException
     {
-        Iterable<ModelModule<EntityModel>> models = moduleInstance.typeLookup().lookupEntityModels( type );
+        Iterable<ModelModule<EntityModel>> models = module.typeLookup().lookupEntityModels( type );
 
         if( !models.iterator().hasNext() )
         {
-            throw new EntityTypeNotFoundException( type.getName() );
+            throw new EntityTypeNotFoundException( type.getName(),
+                                                   module.name(),
+                                                   map( ModelModule.toStringFunction,
+                                                        module.findVisibleEntityTypes()
+                                                   ) );
         }
 
         return uow.get( parseEntityReference( identity ), this, models, type );

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/structure/TypeLookup.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/structure/TypeLookup.java b/core/runtime/src/main/java/org/qi4j/runtime/structure/TypeLookup.java
index 1383ce8..91b49ff 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/structure/TypeLookup.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/structure/TypeLookup.java
@@ -27,7 +27,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import org.qi4j.api.common.Visibility;
 import org.qi4j.api.composite.AmbiguousTypeException;
 import org.qi4j.api.composite.ModelDescriptor;
 import org.qi4j.api.service.NoSuchServiceException;
@@ -39,7 +38,11 @@ import org.qi4j.runtime.composite.TransientModel;
 import org.qi4j.runtime.entity.EntityModel;
 import org.qi4j.runtime.object.ObjectModel;
 import org.qi4j.runtime.value.ValueModel;
+import org.qi4j.spi.module.ModelModule;
 
+import static org.qi4j.api.common.Visibility.application;
+import static org.qi4j.api.common.Visibility.layer;
+import static org.qi4j.api.common.Visibility.module;
 import static org.qi4j.api.util.Classes.RAW_CLASS;
 import static org.qi4j.api.util.Classes.interfacesOf;
 import static org.qi4j.functional.Iterables.cast;
@@ -99,8 +102,9 @@ public class TypeLookup
      *
      * <p>Type lookup is done lazily and cached.</p>
      *
-     * @param type  Looked up Type
-     * @return      First matching Object Model
+     * @param type Looked up Type
+     *
+     * @return First matching Object Model
      */
     @SuppressWarnings( { "raw", "unchecked" } )
     /* package */ ModelModule<ObjectModel> lookupObjectModel( final Class type )
@@ -113,16 +117,20 @@ public class TypeLookup
             Iterable<ModelModule<ObjectModel>> flatten = flatten(
                 ambiguousTypeCheck( type,
                                     findModels( new ExactTypeLookupSpecification( type ),
-                                                moduleInstance.visibleObjects( Visibility.module ),
-                                                moduleInstance.layerInstance().visibleObjects( Visibility.layer ),
-                                                moduleInstance.layerInstance().visibleObjects( Visibility.application ),
-                                                moduleInstance.layerInstance().usedLayersInstance().visibleObjects() ) ),
+                                                moduleInstance.visibleObjects( module ),
+                                                moduleInstance.layerInstance().visibleObjects( layer ),
+                                                moduleInstance.layerInstance().visibleObjects( application ),
+                                                moduleInstance.layerInstance()
+                                                    .usedLayersInstance()
+                                                    .visibleObjects() ) ),
                 ambiguousTypeCheck( type,
                                     findModels( new AssignableTypeLookupSpecification( type ),
-                                                moduleInstance.visibleObjects( Visibility.module ),
-                                                moduleInstance.layerInstance().visibleObjects( Visibility.layer ),
-                                                moduleInstance.layerInstance().visibleObjects( Visibility.application ),
-                                                moduleInstance.layerInstance().usedLayersInstance().visibleObjects() ) ) );
+                                                moduleInstance.visibleObjects( module ),
+                                                moduleInstance.layerInstance().visibleObjects( layer ),
+                                                moduleInstance.layerInstance().visibleObjects( application ),
+                                                moduleInstance.layerInstance()
+                                                    .usedLayersInstance()
+                                                    .visibleObjects() ) ) );
 
             model = first( flatten );
 
@@ -146,8 +154,9 @@ public class TypeLookup
      *
      * <p>Type lookup is done lazily and cached.</p>
      *
-     * @param type  Looked up Type
-     * @return      First matching Transient Model
+     * @param type Looked up Type
+     *
+     * @return First matching Transient Model
      */
     @SuppressWarnings( { "raw", "unchecked" } )
     /* package */ ModelModule<TransientModel> lookupTransientModel( final Class type )
@@ -160,16 +169,22 @@ public class TypeLookup
             Iterable<ModelModule<TransientModel>> allModels = flatten(
                 ambiguousTypeCheck( type,
                                     findModels( new ExactTypeLookupSpecification( type ),
-                                                moduleInstance.visibleTransients( Visibility.module ),
-                                                moduleInstance.layerInstance().visibleTransients( Visibility.layer ),
-                                                moduleInstance.layerInstance().visibleTransients( Visibility.application ),
-                                                moduleInstance.layerInstance().usedLayersInstance().visibleTransients() ) ),
+                                                moduleInstance.visibleTransients( module ),
+                                                moduleInstance.layerInstance().visibleTransients( layer ),
+                                                moduleInstance.layerInstance().visibleTransients( application ),
+                                                moduleInstance.layerInstance().usedLayersInstance().visibleTransients()
+                                    )
+                ),
+
                 ambiguousTypeCheck( type,
                                     findModels( new AssignableTypeLookupSpecification( type ),
-                                                moduleInstance.visibleTransients( Visibility.module ),
-                                                moduleInstance.layerInstance().visibleTransients( Visibility.layer ),
-                                                moduleInstance.layerInstance().visibleTransients( Visibility.application ),
-                                                moduleInstance.layerInstance().usedLayersInstance().visibleTransients() ) ) );
+                                                moduleInstance.visibleTransients( module ),
+                                                moduleInstance.layerInstance().visibleTransients( layer ),
+                                                moduleInstance.layerInstance().visibleTransients( application ),
+                                                moduleInstance.layerInstance().usedLayersInstance().visibleTransients()
+                                    )
+                )
+            );
             model = first( allModels );
 
             if( model != null )
@@ -192,8 +207,9 @@ public class TypeLookup
      *
      * <p>Type lookup is done lazily and cached.</p>
      *
-     * @param type  Looked up Type
-     * @return      First matching Value Model
+     * @param type Looked up Type
+     *
+     * @return First matching Value Model
      */
     @SuppressWarnings( { "raw", "unchecked" } )
     public ModelModule<ValueModel> lookupValueModel( final Class type )
@@ -206,16 +222,19 @@ public class TypeLookup
             Iterable<ModelModule<ValueModel>> flatten = flatten(
                 ambiguousTypeCheck( type,
                                     findModels( new ExactTypeLookupSpecification( type ),
-                                                moduleInstance.visibleValues( Visibility.module ),
-                                                moduleInstance.layerInstance().visibleValues( Visibility.layer ),
-                                                moduleInstance.layerInstance().visibleValues( Visibility.application ),
+                                                moduleInstance.visibleValues( module ),
+                                                moduleInstance.layerInstance().visibleValues( layer ),
+                                                moduleInstance.layerInstance().visibleValues( application ),
                                                 moduleInstance.layerInstance().usedLayersInstance().visibleValues() ) ),
                 ambiguousTypeCheck( type,
                                     findModels( new AssignableTypeLookupSpecification( type ),
-                                                moduleInstance.visibleValues( Visibility.module ),
-                                                moduleInstance.layerInstance().visibleValues( Visibility.layer ),
-                                                moduleInstance.layerInstance().visibleValues( Visibility.application ),
-                                                moduleInstance.layerInstance().usedLayersInstance().visibleValues() ) ) );
+                                                moduleInstance.visibleValues( module ),
+                                                moduleInstance.layerInstance().visibleValues( layer ),
+                                                moduleInstance.layerInstance().visibleValues( application ),
+                                                moduleInstance.layerInstance().usedLayersInstance().visibleValues()
+                                    )
+                )
+            );
 
             model = first( flatten );
 
@@ -242,8 +261,9 @@ public class TypeLookup
      * <p><b>Should be used for creational use cases only.</b> For non-creational use cases see
      * {@link #lookupEntityModels(java.lang.Class)}.</p>
      *
-     * @param type  Looked up Type
-     * @return      First matching Entity Model
+     * @param type Looked up Type
+     *
+     * @return First matching Entity Model
      */
     @SuppressWarnings( { "raw", "unchecked" } )
     /* package */ ModelModule<EntityModel> lookupEntityModel( final Class type )
@@ -256,16 +276,21 @@ public class TypeLookup
             Iterable<ModelModule<EntityModel>> allModels = flatten(
                 ambiguousTypeCheck( type,
                                     findModels( new ExactTypeLookupSpecification( type ),
-                                                moduleInstance.visibleEntities( Visibility.module ),
-                                                moduleInstance.layerInstance().visibleEntities( Visibility.layer ),
-                                                moduleInstance.layerInstance().visibleEntities( Visibility.application ),
-                                                moduleInstance.layerInstance().usedLayersInstance().visibleEntities() ) ),
+                                                moduleInstance.visibleEntities( module ),
+                                                moduleInstance.layerInstance().visibleEntities( layer ),
+                                                moduleInstance.layerInstance().visibleEntities( application ),
+                                                moduleInstance.layerInstance()
+                                                    .usedLayersInstance()
+                                                    .visibleEntities() ) ),
                 ambiguousTypeCheck( type,
                                     findModels( new AssignableTypeLookupSpecification( type ),
-                                                moduleInstance.visibleEntities( Visibility.module ),
-                                                moduleInstance.layerInstance().visibleEntities( Visibility.layer ),
-                                                moduleInstance.layerInstance().visibleEntities( Visibility.application ),
-                                                moduleInstance.layerInstance().usedLayersInstance().visibleEntities() ) ) );
+                                                moduleInstance.visibleEntities( module ),
+                                                moduleInstance.layerInstance().visibleEntities( layer ),
+                                                moduleInstance.layerInstance().visibleEntities( application ),
+                                                moduleInstance.layerInstance().usedLayersInstance().visibleEntities()
+                                    )
+                )
+            );
 
             model = first( allModels );
 
@@ -284,8 +309,8 @@ public class TypeLookup
      * <p>Returned Iterable contains, in order, Entity Models that: </p>
      *
      * <ul>
-     *  <li>exactly match the given type, in Visibility then Assembly order ;</li>
-     *  <li>match a type assignable to the given type, in Visibility then Assembly order.</li>
+     * <li>exactly match the given type, in Visibility then Assembly order ;</li>
+     * <li>match a type assignable to the given type, in Visibility then Assembly order.</li>
      * </ul>
      *
      * <p>Multiple <b>exact</b> matches with the same Visibility are <b>forbidden</b> and result in an AmbiguousTypeException.</p>
@@ -296,8 +321,9 @@ public class TypeLookup
      * <p><b>Should be used for non-creational use cases only.</b> For creational use cases see
      * {@link #lookupEntityModel(java.lang.Class)}.</p>
      *
-     * @param type  Looked up Type
-     * @return      All matching Entity Models
+     * @param type Looked up Type
+     *
+     * @return All matching Entity Models
      */
     @SuppressWarnings( { "raw", "unchecked" } )
     /* package */ Iterable<ModelModule<EntityModel>> lookupEntityModels( final Class type )
@@ -309,14 +335,16 @@ public class TypeLookup
             Iterable<ModelModule<EntityModel>> matchingEntityModels = flatten(
                 ambiguousTypeCheck( type,
                                     findModels( new ExactTypeLookupSpecification( type ),
-                                                moduleInstance.visibleEntities( Visibility.module ),
-                                                moduleInstance.layerInstance().visibleEntities( Visibility.layer ),
-                                                moduleInstance.layerInstance().visibleEntities( Visibility.application ),
-                                                moduleInstance.layerInstance().usedLayersInstance().visibleEntities() ) ),
+                                                moduleInstance.visibleEntities( module ),
+                                                moduleInstance.layerInstance().visibleEntities( layer ),
+                                                moduleInstance.layerInstance().visibleEntities( application ),
+                                                moduleInstance.layerInstance().usedLayersInstance().visibleEntities()
+                                    )
+                ),
                 findModels( new AssignableTypeLookupSpecification( type ),
-                            moduleInstance.visibleEntities( Visibility.module ),
-                            moduleInstance.layerInstance().visibleEntities( Visibility.layer ),
-                            moduleInstance.layerInstance().visibleEntities( Visibility.application ),
+                            moduleInstance.visibleEntities( module ),
+                            moduleInstance.layerInstance().visibleEntities( layer ),
+                            moduleInstance.layerInstance().visibleEntities( application ),
                             moduleInstance.layerInstance().usedLayersInstance().visibleEntities() ) );
 
             // Don't return the same EntityModel multiple times
@@ -335,9 +363,10 @@ public class TypeLookup
      *
      * <p>See {@link #lookupServiceReferences(java.lang.reflect.Type)}.</p>
      *
-     * @param <T>           Service Type
-     * @param serviceType   Looked up Type
-     * @return              First matching ServiceReference
+     * @param <T>         Service Type
+     * @param serviceType Looked up Type
+     *
+     * @return First matching ServiceReference
      */
     /* package */
     @SuppressWarnings( "unchecked" )
@@ -368,8 +397,8 @@ public class TypeLookup
      * <p>Returned Iterable contains, in order, ServiceReferences that: </p>
      *
      * <ul>
-     *  <li>exactly match the given type, in Visibility then Assembly order ;</li>
-     *  <li>match a type assignable to the given type, in Visibility then Assembly order.</li>
+     * <li>exactly match the given type, in Visibility then Assembly order ;</li>
+     * <li>match a type assignable to the given type, in Visibility then Assembly order.</li>
      * </ul>
      *
      * <p>Multiple <b>exact</b> matches with the same Visibility are <b>allowed</b> to enable polymorphic lookup/injection.</p>
@@ -377,9 +406,10 @@ public class TypeLookup
      *
      * <p>Type lookup is done lazily and cached.</p>
      *
-     * @param <T>           Service Type
-     * @param serviceType   Looked up Type
-     * @return              All matching ServiceReferences
+     * @param <T>         Service Type
+     * @param serviceType Looked up Type
+     *
+     * @return All matching ServiceReferences
      */
     @SuppressWarnings( "unchecked" )
     /* package */ <T> Iterable<ServiceReference<T>> lookupServiceReferences( final Type serviceType )
@@ -390,14 +420,14 @@ public class TypeLookup
             // Lazily resolve ServicesReferences
             Iterable<ServiceReference<?>> matchingServices = flatten(
                 findServiceReferences( new ExactTypeLookupSpecification( serviceType ),
-                                       moduleInstance.visibleServices( Visibility.module ),
-                                       moduleInstance.layerInstance().visibleServices( Visibility.layer ),
-                                       moduleInstance.layerInstance().visibleServices( Visibility.application ),
+                                       moduleInstance.visibleServices( module ),
+                                       moduleInstance.layerInstance().visibleServices( layer ),
+                                       moduleInstance.layerInstance().visibleServices( application ),
                                        moduleInstance.layerInstance().usedLayersInstance().visibleServices() ),
                 findServiceReferences( new AssignableTypeLookupSpecification( serviceType ),
-                                       moduleInstance.visibleServices( Visibility.module ),
-                                       moduleInstance.layerInstance().visibleServices( Visibility.layer ),
-                                       moduleInstance.layerInstance().visibleServices( Visibility.application ),
+                                       moduleInstance.visibleServices( module ),
+                                       moduleInstance.layerInstance().visibleServices( layer ),
+                                       moduleInstance.layerInstance().visibleServices( application ),
                                        moduleInstance.layerInstance().usedLayersInstance().visibleServices() ) );
 
             // Don't return the same ServiceReference multiple times
@@ -412,7 +442,8 @@ public class TypeLookup
 
     @SuppressWarnings( { "raw", "unchecked" } )
     private static <T extends ModelDescriptor> Iterable<ModelModule<T>> findModels( Specification<Iterable<Class<?>>> specification,
-                                                                                    Iterable<ModelModule<T>>... models )
+                                                                                    Iterable<ModelModule<T>>... models
+    )
     {
         Specification<ModelModule<T>> spec = Specifications.translate( new ModelModuleTypesFunction(), specification );
         Iterable<ModelModule<T>> flattened = flattenIterables( iterable( models ) );
@@ -421,7 +452,8 @@ public class TypeLookup
 
     @SuppressWarnings( { "raw", "unchecked" } )
     private static Iterable<ServiceReference<?>> findServiceReferences( Specification<Iterable<Class<?>>> specification,
-                                                                        Iterable<ServiceReference<?>>... references )
+                                                                        Iterable<ServiceReference<?>>... references
+    )
     {
         Specification<ServiceReference<?>> spec = Specifications.translate( new ServiceReferenceTypesFunction(), specification );
         Iterable<ServiceReference<?>> flattened = flattenIterables( iterable( references ) );
@@ -434,7 +466,8 @@ public class TypeLookup
      */
     @SuppressWarnings( "raw" )
     private static <T extends ModelDescriptor> Iterable<ModelModule<T>> ambiguousTypeCheck( final Class type,
-                                                                                            final Iterable<ModelModule<T>> models )
+                                                                                            final Iterable<ModelModule<T>> models
+    )
     {
         return new Iterable<ModelModule<T>>()
         {
@@ -473,7 +506,6 @@ public class TypeLookup
                 // Ambiguity check done, and no ambiguities found. Return results
                 return results.iterator();
             }
-
         };
     }
 
@@ -486,7 +518,6 @@ public class TypeLookup
         {
             return modelModule.model().types();
         }
-
     }
 
     private static class ServiceReferenceTypesFunction
@@ -498,7 +529,6 @@ public class TypeLookup
         {
             return serviceReference.types();
         }
-
     }
 
     private static abstract class AbstractTypeLookupSpecification
@@ -563,7 +593,6 @@ public class TypeLookup
         }
 
         protected abstract boolean checkClassMatch( Class<?> candidate, Class<?> lookedUpType );
-
     }
 
     private static final class ExactTypeLookupSpecification
@@ -580,7 +609,6 @@ public class TypeLookup
         {
             return candidate.equals( lookedUpType );
         }
-
     }
 
     private static final class AssignableTypeLookupSpecification
@@ -597,7 +625,5 @@ public class TypeLookup
         {
             return !candidate.equals( lookedUpType ) && lookedUpType.isAssignableFrom( candidate );
         }
-
     }
-
 }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/structure/UsedLayersInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/structure/UsedLayersInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/structure/UsedLayersInstance.java
index 1c0f650..7eb57b9 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/structure/UsedLayersInstance.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/structure/UsedLayersInstance.java
@@ -16,12 +16,17 @@ package org.qi4j.runtime.structure;
 
 import java.util.List;
 import org.qi4j.api.common.Visibility;
+import org.qi4j.api.composite.TransientDescriptor;
+import org.qi4j.api.entity.EntityDescriptor;
+import org.qi4j.api.object.ObjectDescriptor;
 import org.qi4j.api.service.ServiceReference;
+import org.qi4j.api.value.ValueDescriptor;
 import org.qi4j.functional.Function;
 import org.qi4j.runtime.composite.TransientModel;
 import org.qi4j.runtime.entity.EntityModel;
 import org.qi4j.runtime.object.ObjectModel;
 import org.qi4j.runtime.value.ValueModel;
+import org.qi4j.spi.module.ModelModule;
 
 import static org.qi4j.functional.Iterables.*;
 
@@ -37,48 +42,48 @@ public final class UsedLayersInstance
         this.usedLayerInstances = usedLayerInstances;
     }
 
-    /* package */ Iterable<ModelModule<ObjectModel>> visibleObjects()
+    /* package */ Iterable<ModelModule<ObjectDescriptor>> visibleObjects()
     {
-        return flattenIterables( map( new Function<LayerInstance, Iterable<ModelModule<ObjectModel>>>()
+        return flattenIterables( map( new Function<LayerInstance, Iterable<ModelModule<ObjectDescriptor>>>()
         {
             @Override
-            public Iterable<ModelModule<ObjectModel>> map( LayerInstance layerInstance )
+            public Iterable<ModelModule<ObjectDescriptor>> map( LayerInstance layerInstance )
             {
                 return layerInstance.visibleObjects( Visibility.application );
             }
         }, usedLayerInstances ) );
     }
 
-    /* package */ Iterable<ModelModule<TransientModel>> visibleTransients()
+    /* package */ Iterable<ModelModule<TransientDescriptor>> visibleTransients()
     {
-        return flattenIterables( map( new Function<LayerInstance, Iterable<ModelModule<TransientModel>>>()
+        return flattenIterables( map( new Function<LayerInstance, Iterable<ModelModule<TransientDescriptor>>>()
         {
             @Override
-            public Iterable<ModelModule<TransientModel>> map( LayerInstance layerInstance )
+            public Iterable<ModelModule<TransientDescriptor>> map( LayerInstance layerInstance )
             {
                 return layerInstance.visibleTransients( Visibility.application );
             }
         }, usedLayerInstances ) );
     }
 
-    /* package */ Iterable<ModelModule<EntityModel>> visibleEntities()
+    /* package */ Iterable<ModelModule<EntityDescriptor>> visibleEntities()
     {
-        return flattenIterables( map( new Function<LayerInstance, Iterable<ModelModule<EntityModel>>>()
+        return flattenIterables( map( new Function<LayerInstance, Iterable<ModelModule<EntityDescriptor>>>()
         {
             @Override
-            public Iterable<ModelModule<EntityModel>> map( LayerInstance layerInstance )
+            public Iterable<ModelModule<EntityDescriptor>> map( LayerInstance layerInstance )
             {
                 return layerInstance.visibleEntities( Visibility.application );
             }
         }, usedLayerInstances ) );
     }
 
-    /* package */ Iterable<ModelModule<ValueModel>> visibleValues()
+    /* package */ Iterable<ModelModule<ValueDescriptor>> visibleValues()
     {
-        return flattenIterables( map( new Function<LayerInstance, Iterable<ModelModule<ValueModel>>>()
+        return flattenIterables( map( new Function<LayerInstance, Iterable<ModelModule<ValueDescriptor>>>()
         {
             @Override
-            public Iterable<ModelModule<ValueModel>> map( LayerInstance layerInstance )
+            public Iterable<ModelModule<ValueDescriptor>> map( LayerInstance layerInstance )
             {
                 return layerInstance.visibleValues( Visibility.application );
             }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/0b9b6555/core/runtime/src/main/java/org/qi4j/runtime/unitofwork/EntityBuilderInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/unitofwork/EntityBuilderInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/unitofwork/EntityBuilderInstance.java
index eae69b1..ff17a07 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/unitofwork/EntityBuilderInstance.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/unitofwork/EntityBuilderInstance.java
@@ -24,7 +24,7 @@ import org.qi4j.api.entity.LifecycleException;
 import org.qi4j.runtime.composite.FunctionStateResolver;
 import org.qi4j.runtime.entity.EntityInstance;
 import org.qi4j.runtime.entity.EntityModel;
-import org.qi4j.runtime.structure.ModelModule;
+import org.qi4j.spi.module.ModelModule;
 import org.qi4j.runtime.structure.ModuleUnitOfWork;
 import org.qi4j.spi.entity.EntityState;
 import org.qi4j.spi.entitystore.EntityStoreUnitOfWork;


Mime
View raw message