# DockerfileFactoryContext Properties

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [DockerfileFactoryContext](/reference/api/csharp/aspire.hosting/dockerfilefactorycontext.md)
- Kind: `Properties`
- Members: `3`

Provides context for Dockerfile factory functions.

## CancellationToken

- Name: `CancellationToken`
- Modifiers: `get; init`
- Returns: `CancellationToken`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/DockerfileFactoryContext.cs)

Gets the cancellation token for the operation.

```csharp
public CancellationToken CancellationToken { get; init; }
```

## Resource

- Name: `Resource`
- Modifiers: `get; init`
- Returns: [IResource](/reference/api/csharp/aspire.hosting/iresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/DockerfileFactoryContext.cs)

Gets the resource for which the Dockerfile is being generated.

This allows factory functions to query resource annotations and properties to customize the generated Dockerfile.

```csharp
var containerAnnotation = context.Resource.Annotations.OfType<ContainerImageAnnotation>().FirstOrDefault();
var baseImage = containerAnnotation?.Image ?? "alpine:latest";
```

```csharp
public IResource Resource { get; init; }
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## Services

- Name: `Services`
- Modifiers: `get; init`
- Returns: `IServiceProvider`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/ApplicationModel/DockerfileFactoryContext.cs)

Gets the `IServiceProvider` for resolving dependencies required by Dockerfile factory functions.

The service provider typically contains services such as `IHostEnvironment`, `ILogger`, and configuration objects relevant to the application model. Factory functions can use this provider to obtain required services for generating Dockerfiles.

```csharp
var logger = context.Services.GetRequiredService<ILogger>();
```

```csharp
public IServiceProvider Services { get; init; }
```
