Finding Service Instances Below A Root Path
4 min
Overview
In Activate, service instances can be queried relative to a specific service tree location. This allows you to retrieve all service instances, or only those that exist under a defined service root.
This approach is commonly used in scripts where service instances need to be filtered by structure rather than by individual service names.
How Service Root Filtering Works
The Services collection exposed on a user supports path-based access.
By passing a service root path, Activate returns a ServiceInstanceCollection containing all matching service instances beneath that path.
Wildcard paths can be used to include all child services.
Example Usage
The following example demonstrates retrieving:
- All service instances assigned to the current user
- Only service instances under a specific sub-tree
ServiceInstanceCollection col1 = CurrentUser.Services["//Services/*"] as ServiceInstanceCollection;
ServiceInstanceCollection col2 = CurrentUser.Services["//Services/Examples/*"] as ServiceInstanceCollection;
Trace.WriteLine($"All service instances count: {col1.Count}");
Trace.WriteLine($"Examples service (and child service instances) instances count: {col2.Count}");
Common Use Cases
This pattern is useful when you need to:
- Process or report on all services assigned to a user
- Restrict logic to services under a specific folder or category
- Compare service usage across different service branches
Notes and Considerations
- Ensure the path exists in the service tree
- Use wildcards to include child services
- Results are limited to services assigned to the target user