# AddDockerfileFactory

- Module: [Aspire.Hosting](/reference/api/go/aspire.hosting.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: [`DistributedApplicationBuilder`](/reference/api/go/aspire.hosting/distributedapplicationbuilder.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/bcfa151cdca6d0a573f22d5d9c23f9c727cb3b2f)

Adds a Dockerfile to the application model that can be treated like a container resource, with the Dockerfile content generated by an asynchronous factory function.

## Remarks

The `contextPath` is relative to the AppHost directory unless it is fully qualified.
The factory function is invoked once during the build process to generate the Dockerfile content.
The output is trusted and not validated.

## Definition

```go
func (DistributedApplicationBuilder) AddDockerfileFactory(
    name string,
    contextPath string,
    dockerfileFactory func(arg DockerfileFactoryContext) string,
    options ...*AddDockerfileFactoryOptions,
) ContainerResource
```

## Parameters

- `name` (`string`) -- The name of the resource.
- `contextPath` (`string`) -- Path to be used as the context for the container image build.
- `dockerfileFactory` (`func(arg DockerfileFactoryContext) string`) -- An asynchronous function that returns the Dockerfile content as a string.
- `options` (`...*AddDockerfileFactoryOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*AddDockerfileFactoryOptions` argument.

- `Stage` (`*string`) -- The stage representing the image to be published in a multi-stage Dockerfile.

## Returns

[`ContainerResource`](/reference/api/go/aspire.hosting/containerresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`DistributedApplicationBuilder`](/reference/api/go/aspire.hosting/distributedapplicationbuilder.md)
