# IResourceWithEnvironment.withReference

- Module: [Aspire.Hosting](/reference/api/typescript/aspire.hosting.md)
- Defined on: [IResourceWithEnvironment](/reference/api/typescript/aspire.hosting/iresourcewithenvironment.md)
- Version: `13.4.0`
- Kind: `method`

Adds a reference to another resource

## Definition

```typescript
interface IResourceWithEnvironment {
  // ... omitted for brevity
  withReference(
      source: EndpointReference|string|uri,
      connectionName?: string,
      optional?: boolean,
      name?: string): IResourceWithEnvironment;
}
```

## Signature

```typescript
withReference(
    source: EndpointReference|string|uri,
    connectionName?: string,
    optional?: boolean,
    name?: string): IResourceWithEnvironment
```

## Parameters

- `source` (`EndpointReference|string|uri`)
- `connectionName` (`string`) `optional`
- `optional` (`boolean`) `optional` `= False`
- `name` (`string`) `optional`

## Returns

[IResourceWithEnvironment](/reference/api/typescript/aspire.hosting/iresourcewithenvironment.md) `builder`

## Defined on

- [IResourceWithEnvironment](/reference/api/typescript/aspire.hosting/iresourcewithenvironment.md) -- `interface`
