> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::FragmentServiceProvider

> Interface for classes that can provide access to registered fragment services.

Interface for classes that can provide access to registered fragment services.

This interface is used by [ComponentBase](componentbase) to decouple component service access from the concrete [Fragment](fragment) implementation, enabling better testability and modularity while still allowing service retrieval.

```cpp showLineNumbers={false}
#include <holoscan/fragment_service_provider.hpp>
```

---

## Constructors

### Destructor \[#destructor]

### \~FragmentServiceProvider

```cpp showLineNumbers={false}
virtual holoscan::FragmentServiceProvider::~FragmentServiceProvider() = default
```

---

## Methods

### get\_service\_erased \[#getserviceerased]

```cpp showLineNumbers={false}
virtual std::shared_ptr<FragmentService> holoscan::FragmentServiceProvider::get_service_erased(
    const std::type_info &service_type,
    std::string_view id
) const
```

Retrieves a service using type erasure.

**Returns:** A shared\_ptr to [FragmentService](fragmentservice) if found, otherwise nullptr.

**Parameters**

**`service_type`** `const std::type_info &`

The std::type\_info of the service to retrieve.

---

**`id`** `std::string_view`

The identifier of the service instance.

---

### get\_service\_resource\_by\_name \[#getserviceresourcebyname]

```cpp showLineNumbers={false}
virtual std::shared_ptr<Resource> holoscan::FragmentServiceProvider::get_service_resource_by_name(
    std::string_view id
) const
```

Retrieve a resource registered as a fragment service by name.

**Returns:** A shared\_ptr to the service resource, or nullptr if not found.

**Parameters**

**`id`** `std::string_view`

The service id (name) used during service registration.

---

### get\_services\_by\_id \[#getservicesbyid]

```cpp showLineNumbers={false}
virtual std::vector<std::shared_ptr<FragmentService>> holoscan::FragmentServiceProvider::get_services_by_id(
    std::string_view id
) const
```

Retrieve all fragment services with a matching id, regardless of registered type.

This method is used as a fallback when exact type lookup fails, enabling retrieval of services registered with a derived type when looking up by a base type.

**Returns:** A vector of shared\_ptrs to matching FragmentServices. Empty if none found.

**Parameters**

**`id`** `std::string_view`

The service id (name) used during service registration.

---