Skip to content
DocsTry Aspire
DocsTry

Service Methods

ClassMethods4 members
Represents a Docker Compose service definition.
Adds a configuration reference to the service's list of configurations. This method allows you to include external configuration resources that the service can utilize at runtime.
public sealed class Service
{
public Service AddConfig(
ConfigReference config)
{
// ...
}
}
configConfigReferenceThe config reference to add
ServiceThe updated Service instance with the added environmental variable.
Adds an environmental variable to the service's environment dictionary. If the specified value is null, it assigns an empty string as the value.
public sealed class Service
{
public Service AddEnvironmentalVariable(
string key,
string? value)
{
// ...
}
}
keystringThe key for the environmental variable.
valuestring?The value of the environmental variable. If null, an empty string will be used.
ServiceThe updated Service instance with the added environmental variable.
Adds a volume to the service's list of volumes. If the volumes collection is null, it initializes a new collection before adding the volume.
public sealed class Service
{
public Service AddVolume(
Volume volume)
{
// ...
}
}
volumeVolumeThe volume to be added to the service.
ServiceThe updated Service instance with the added volume.
Adds multiple volumes to the service's list of volumes. If the volumes collection is empty, the provided volumes will be appended to the existing collection.
public sealed class Service
{
public Service AddVolumes(
IEnumerable<Volume> volumes)
{
// ...
}
}
volumesIEnumerable<Volume>A collection of volumes to be added to the service.
ServiceThe updated Service instance with the added volumes.