# ContainerResource.withDockerfileFactory

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

Builds the specified container image from a Dockerfile generated by an asynchronous factory function.

## Definition

```typescript
interface ContainerResource {
  // ... omitted for brevity
  withDockerfileFactory(contextPath: string, dockerfileFactory: (arg: DockerfileFactoryContext) => Promise<string>, stage?: string): ContainerResource;
}
```

## Signature

```typescript
withDockerfileFactory(contextPath: string, dockerfileFactory: (arg: DockerfileFactoryContext) => Promise<string>, stage?: string): ContainerResource
```

## Parameters

- `contextPath` (`string`)
- `dockerfileFactory` (`(arg: DockerfileFactoryContext) => Promise<string>`)
- `stage` (`string`) `optional`

## Returns

[ContainerResource](/reference/api/typescript/aspire.hosting/containerresource.md) `builder`

## Defined on

- [ContainerResource](/reference/api/typescript/aspire.hosting/containerresource.md) -- `handle`
