Source:
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ServiceName depUnitServiceName = deploymentUnit.getServiceName(); final DeploymentUnit parent = deploymentUnit.getParent(); final DeploymentUnit topLevelDeployment = parent == null ? deploymentUnit : parent; final ExternalModule externalModuleService = topLevelDeployment.getAttachment(Attachments.EXTERNAL_MODULE_SERVICE); final ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); final CapabilityServiceSupport capabilitySupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); final ServiceRegistry serviceRegistry = phaseContext.getServiceRegistry(); final ServiceTarget target = phaseContext.getServiceTarget(); final ServiceTarget externalServiceTarget = deploymentUnit.getAttachment(Attachments.EXTERNAL_SERVICE_TARGET); final ServiceName allDirReadyServiceName = depUnitServiceName.append("directory-services-ready"); final ServiceBuilder<?> allDirReadyServiceBuilder = target.addService(allDirReadyServiceName); final List<Supplier<GlobalDirectoryResourceDefinition.GlobalDirectory>> allDirReadySuppliers = new ArrayList<>(); List<ServiceName> serviceNames = serviceRegistry.getServiceNames(); for (ServiceName serviceName : serviceNames) { if (capabilitySupport.getCapabilityServiceName(EE_GLOBAL_DIRECTORY_CAPABILITY_NAME).isParentOf(serviceName)) { Supplier<GlobalDirectoryResourceDefinition.GlobalDirectory> pathRequirement = allDirReadyServiceBuilder.requires(serviceName); allDirReadySuppliers.add(pathRequirement); } } if (!allDirReadySuppliers.isEmpty()) { GlobalDirectoryDeploymentService globalDirDepService = new GlobalDirectoryDeploymentService(allDirReadySuppliers, externalModuleService, moduleSpecification, moduleLoader, serviceRegistry, externalServiceTarget); allDirReadyServiceBuilder.requires(phaseContext.getPhaseServiceName()); allDirReadyServiceBuilder.setInstance(globalDirDepService) .install(); phaseContext.requires(allDirReadyServiceName, new DelegatingSupplier()); } }

Target:
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ServiceName depUnitServiceName = deploymentUnit.getServiceName(); final DeploymentUnit parent = deploymentUnit.getParent(); final DeploymentUnit topLevelDeployment = parent == null ? deploymentUnit : parent; final ExternalModule externalModuleService = topLevelDeployment.getAttachment(Attachments.EXTERNAL_MODULE_SERVICE); final ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); final CapabilityServiceSupport capabilitySupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); final ServiceRegistry serviceRegistry = phaseContext.getServiceRegistry(); final ServiceTarget target = phaseContext.getServiceTarget(); final ServiceTarget externalServiceTarget = deploymentUnit.getAttachment(Attachments.EXTERNAL_SERVICE_TARGET); final ServiceName allDirReadyServiceName = depUnitServiceName.append("directory-services-ready"); final ServiceBuilder<?> allDirReadyServiceBuilder = target.addService(allDirReadyServiceName); final List<Supplier<GlobalDirectoryResourceDefinition.GlobalDirectory>> allDirReadySuppliers = new ArrayList<>(); final ServiceName csName = capabilitySupport.getCapabilityServiceName(EE_GLOBAL_DIRECTORY_CAPABILITY_NAME); List<ServiceName> serviceNames = serviceRegistry.getServiceNames(); for (ServiceName serviceName : serviceNames) { if (csName.isParentOf(serviceName)) { Supplier<GlobalDirectoryResourceDefinition.GlobalDirectory> pathRequirement = allDirReadyServiceBuilder.requires(serviceName); allDirReadySuppliers.add(pathRequirement); } } if (!allDirReadySuppliers.isEmpty()) { GlobalDirectoryDeploymentService globalDirDepService = new GlobalDirectoryDeploymentService(allDirReadySuppliers, externalModuleService, moduleSpecification, moduleLoader, serviceRegistry, externalServiceTarget); allDirReadyServiceBuilder.requires(phaseContext.getPhaseServiceName()); allDirReadyServiceBuilder.setInstance(globalDirDepService) .install(); phaseContext.requires(allDirReadyServiceName, new DelegatingSupplier()); } }