# IResource

- Module: [Aspire.Hosting](/reference/api/typescript/aspire.hosting.md)
- Version: `13.4.0`
- Kind: `interface`
- Source: [GitHub](https://github.com/microsoft/aspire)

Represents a resource that can be hosted by an application.

## Definition

```typescript
interface IResource {
  createExecutionConfiguration(): IExecutionConfigurationBuilder;
  excludeFromManifest(): IResource;
  excludeFromMcp(): IResource;
  getResourceName(): string;
  onBeforeResourceStarted(callback: (arg: BeforeResourceStartedEvent) => Promise<void>): IResource;
  onInitializeResource(callback: (arg: InitializeResourceEvent) => Promise<void>): IResource;
  onResourceReady(callback: (arg: ResourceReadyEvent) => Promise<void>): IResource;
  onResourceStopped(callback: (arg: ResourceStoppedEvent) => Promise<void>): IResource;
  withChildRelationship(child: IResource): IResource;
  withCommand(name: string, displayName: string, executeCommand: (arg: ExecuteCommandContext) => Promise<ExecuteCommandResult>, commandOptions?: CommandOptions): IResource;
  withContainerRegistry(registry: IResource): IResource;
  withDockerfileBaseImage(
      buildImage?: string,
      runtimeImage?: string): IResource;
  withExplicitStart(): IResource;
  withHealthCheck(key: string): IResource;
  withHidden(): IResource;
  withHiddenOnCompletion(
      exitCode?: number,
      exitCodes?: number[]): IResource;
  withIconName(
      iconName: string,
      iconVariant?: IconVariant): IResource;
  withLifetimeOf(sourceBuilder: IResource): IResource;
  withParentProcessLifetime(parentProcessId: number): IResource;
  withParentRelationship(parent: IResource): IResource;
  withPersistentLifetime(): IResource;
  withPipelineConfiguration(callback: (obj: PipelineConfigurationContext) => Promise<void>): IResource;
  withPipelineStepFactory(stepName: string, callback: (arg: PipelineStepContext) => Promise<void>, dependsOn?: string[], requiredBy?: string[], tags?: string[], description?: string): IResource;
  withProcessCommand(
      commandName: string,
      displayName: string,
      options: ProcessCommandExportOptions): IResource;
  withProcessCommandFactory(commandName: string, displayName: string, createProcessSpec: (arg: ExecuteCommandContext) => Promise<ProcessCommandSpecExportData>, options?: ProcessCommandResultExportOptions): IResource;
  withRelationship(
      resourceBuilder: IResource,
      type: string): IResource;
  withRequiredCommand(
      command: string,
      helpLink?: string): IResource;
  withSessionLifetime(): IResource;
  withUrl(
      url: ReferenceExpression,
      displayText?: string): IResource;
  withUrlForEndpoint(endpointName: string, callback: (obj: ResourceUrlAnnotation) => Promise<void>): IResource;
  withUrls(callback: (obj: ResourceUrlsCallbackContext) => Promise<void>): IResource;
}
```

## Methods

- [createExecutionConfiguration](/reference/api/typescript/aspire.hosting/iresource/createexecutionconfiguration.md) -- `method` -- Creates an execution configuration builder for the specified resource.
    ```typescript
  createExecutionConfiguration(): IExecutionConfigurationBuilder
  ```
- [excludeFromManifest](/reference/api/typescript/aspire.hosting/iresource/excludefrommanifest.md) -- `method` -- Excludes a resource from being published to the manifest.
    ```typescript
  excludeFromManifest(): IResource
  ```
- [excludeFromMcp](/reference/api/typescript/aspire.hosting/iresource/excludefrommcp.md) -- `method` -- Exclude the resource from MCP operations using the Aspire MCP server. The resource is excluded from results that return resources, console logs and telemetry.
    ```typescript
  excludeFromMcp(): IResource
  ```
- [getResourceName](/reference/api/typescript/aspire.hosting/iresource/getresourcename.md) -- `method` -- Gets the name of the resource from a builder.
    ```typescript
  getResourceName(): string
  ```
- [onBeforeResourceStarted](/reference/api/typescript/aspire.hosting/iresource/onbeforeresourcestarted.md) -- `method` -- Subscribes to the BeforeResourceStarted event.
    ```typescript
  onBeforeResourceStarted(callback: (arg: BeforeResourceStartedEvent) => Promise<void>): IResource
  ```
- [onInitializeResource](/reference/api/typescript/aspire.hosting/iresource/oninitializeresource.md) -- `method` -- Subscribes to the InitializeResource event.
    ```typescript
  onInitializeResource(callback: (arg: InitializeResourceEvent) => Promise<void>): IResource
  ```
- [onResourceReady](/reference/api/typescript/aspire.hosting/iresource/onresourceready.md) -- `method` -- Subscribes to the ResourceReady event.
    ```typescript
  onResourceReady(callback: (arg: ResourceReadyEvent) => Promise<void>): IResource
  ```
- [onResourceStopped](/reference/api/typescript/aspire.hosting/iresource/onresourcestopped.md) -- `method` -- Subscribes to the ResourceStopped event.
    ```typescript
  onResourceStopped(callback: (arg: ResourceStoppedEvent) => Promise<void>): IResource
  ```
- [withChildRelationship](/reference/api/typescript/aspire.hosting/iresource/withchildrelationship.md) -- `method` -- Sets a child relationship
    ```typescript
  withChildRelationship(child: IResource): IResource
  ```
- [withCommand](/reference/api/typescript/aspire.hosting/iresource/withcommand.md) -- `method` -- Adds a resource command
    ```typescript
  withCommand(name: string, displayName: string, executeCommand: (arg: ExecuteCommandContext) => Promise<ExecuteCommandResult>, commandOptions?: CommandOptions): IResource
  ```
- [withContainerRegistry](/reference/api/typescript/aspire.hosting/iresource/withcontainerregistry.md) -- `method` -- Configures the resource to use the specified container registry for container image operations.
    ```typescript
  withContainerRegistry(registry: IResource): IResource
  ```
- [withDockerfileBaseImage](/reference/api/typescript/aspire.hosting/iresource/withdockerfilebaseimage.md) -- `method` -- Configures custom base images for generated Dockerfiles.
    ```typescript
  withDockerfileBaseImage(buildImage?: string, runtimeImage?: string): IResource
  ```
- [withExplicitStart](/reference/api/typescript/aspire.hosting/iresource/withexplicitstart.md) -- `method` -- Prevents resource from starting automatically
    ```typescript
  withExplicitStart(): IResource
  ```
- [withHealthCheck](/reference/api/typescript/aspire.hosting/iresource/withhealthcheck.md) -- `method` -- Adds a health check by key
    ```typescript
  withHealthCheck(key: string): IResource
  ```
- [withHidden](/reference/api/typescript/aspire.hosting/iresource/withhidden.md) -- `method` -- Hides the resource from default resource lists
    ```typescript
  withHidden(): IResource
  ```
- [withHiddenOnCompletion](/reference/api/typescript/aspire.hosting/iresource/withhiddenoncompletion.md) -- `method` -- Hides the resource from default resource lists after successful completion
    ```typescript
  withHiddenOnCompletion(exitCode?: number, exitCodes?: number[]): IResource
  ```
- [withIconName](/reference/api/typescript/aspire.hosting/iresource/withiconname.md) -- `method` -- Specifies the icon to use when displaying the resource in the dashboard.
    ```typescript
  withIconName(iconName: string, iconVariant?: IconVariant): IResource
  ```
- [withLifetimeOf](/reference/api/typescript/aspire.hosting/iresource/withlifetimeof.md) -- `method` -- Configures a resource to match the lifetime of another resource.
    ```typescript
  withLifetimeOf(sourceBuilder: IResource): IResource
  ```
- [withParentProcessLifetime](/reference/api/typescript/aspire.hosting/iresource/withparentprocesslifetime.md) -- `method` -- Configures a resource to use a persistent lifetime that ends when a parent process exits.
    ```typescript
  withParentProcessLifetime(parentProcessId: number): IResource
  ```
- [withParentRelationship](/reference/api/typescript/aspire.hosting/iresource/withparentrelationship.md) -- `method` -- Sets the parent relationship
    ```typescript
  withParentRelationship(parent: IResource): IResource
  ```
- [withPersistentLifetime](/reference/api/typescript/aspire.hosting/iresource/withpersistentlifetime.md) -- `method` -- Configures a resource to use a persistent lifetime.
    ```typescript
  withPersistentLifetime(): IResource
  ```
- [withPipelineConfiguration](/reference/api/typescript/aspire.hosting/iresource/withpipelineconfiguration.md) -- `method` -- Registers a callback to be executed during the pipeline configuration phase, allowing modification of step dependencies and relationships.
    ```typescript
  withPipelineConfiguration(callback: (obj: PipelineConfigurationContext) => Promise<void>): IResource
  ```
- [withPipelineStepFactory](/reference/api/typescript/aspire.hosting/iresource/withpipelinestepfactory.md) -- `method` -- Adds a pipeline step to the resource that will be executed during deployment.
    ```typescript
  withPipelineStepFactory(stepName: string, callback: (arg: PipelineStepContext) => Promise<void>, dependsOn?: string[], requiredBy?: string[], tags?: string[], description?: string): IResource
  ```
- [withProcessCommand](/reference/api/typescript/aspire.hosting/iresource/withprocesscommand.md) -- `method` -- Adds a command to the resource that starts a local process when invoked.
    ```typescript
  withProcessCommand(commandName: string, displayName: string, options: ProcessCommandExportOptions): IResource
  ```
- [withProcessCommandFactory](/reference/api/typescript/aspire.hosting/iresource/withprocesscommandfactory.md) -- `method` -- Adds a command to the resource that starts a local process created by a callback when invoked.
    ```typescript
  withProcessCommandFactory(commandName: string, displayName: string, createProcessSpec: (arg: ExecuteCommandContext) => Promise<ProcessCommandSpecExportData>, options?: ProcessCommandResultExportOptions): IResource
  ```
- [withRelationship](/reference/api/typescript/aspire.hosting/iresource/withrelationship.md) -- `method` -- Adds a relationship to another resource using its builder.
    ```typescript
  withRelationship(resourceBuilder: IResource, type: string): IResource
  ```
- [withRequiredCommand](/reference/api/typescript/aspire.hosting/iresource/withrequiredcommand.md) -- `method` -- Declares that a resource requires a specific command/executable to be available on the local machine PATH before it can start.
    ```typescript
  withRequiredCommand(command: string, helpLink?: string): IResource
  ```
- [withSessionLifetime](/reference/api/typescript/aspire.hosting/iresource/withsessionlifetime.md) -- `method` -- Configures a resource to use a session lifetime.
    ```typescript
  withSessionLifetime(): IResource
  ```
- [withUrl](/reference/api/typescript/aspire.hosting/iresource/withurl.md) -- `method` -- Adds or modifies displayed URLs
    ```typescript
  withUrl(url: ReferenceExpression, displayText?: string): IResource
  ```
- [withUrlForEndpoint](/reference/api/typescript/aspire.hosting/iresource/withurlforendpoint.md) -- `method` -- Registers a callback to update the URL displayed for the endpoint with the specified name.
    ```typescript
  withUrlForEndpoint(endpointName: string, callback: (obj: ResourceUrlAnnotation) => Promise<void>): IResource
  ```
- [withUrls](/reference/api/typescript/aspire.hosting/iresource/withurls.md) -- `method` -- Registers a callback to customize the URLs displayed for the resource.
    ```typescript
  withUrls(callback: (obj: ResourceUrlsCallbackContext) => Promise<void>): IResource
  ```
