> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dairy.foundation/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

Dairy supports configuration by discovery using Sinister.

This system allows for a global static instance to be configured just after
instantiation by user code.

For the moment, nothing exists in Core for users that they need to use this for,
but it is used in the Test runtime, and is a useful feature for library authors.

Configurable:

<CodeGroup>
  ```java Java theme={null}
  public class Settings implements Configurable {
  	private Settings() {}
  	public static Settings INSTANCE = new Settings();
  	private int teamNumber;

  	public int getTeamNumber() {
  		return teamNumber;
  	}

  	public void setTeamNumber(int teamNumber) {
  		this.teamNumber = teamNumber;
  	}
  }
  ```

  ```kt Kotlin theme={null}
  object Settings : Configurable {
  	var teamNumber: Int = 0
  }
  ```
</CodeGroup>

Configuration:

<CodeGroup>
  ```java Java theme={null}
  public class SettingsConfig implements Configuration<Settings> {
  	private SettingsConfig() {}
  	public static SettingsConfig INSTANCE = new SettingsConfig();
  	@NonNull
  	@Override
  	public Class<Settings> getConfigurableClass() {
  		return Settings.class;
  	}

  	@Override
  	public void configure(@NonNull Settings configurable) {
  		configurable.setTeamNumber(14349);
  	}

  	@NonNull
  	@Override
  	public List<Configuration<? super Settings>> getPrioritisedOver() {
  		return Collections.emptyList();
  	}
  }
  ```

  ```kt Kotlin theme={null}
  object SettingsConfig : Configuration<Settings> {
  	override val configurableClass = Settings::class.java
  	override val prioritisedOver = emptyList<Configuration<in Settings>>()
  	override fun configure(configurable: Settings) {
  		configurable.teamNumber = 14349
  	}
  }
  ```
</CodeGroup>

The configure method of `SettingsConfig` will be called when the robot boots up,
and it will configure the `INSTANCE` of `Settings`.

# Overriding Configurations:

A configuration will automatically be overridden if:

* It was in a dairy library's package.
* It was in a library, and your configuration was in TeamCode.

This means that a library can add a configuration for something in Dairy to
automatically configure it, and a team can add a configuration to their code to
override both other libraries and Dairy.

If configurations can't figure out one single configuration to apply, a warning
will be logged out, and it will tell you the offenders, then apply all of them.

If you get the warnings, you will need to either add a configuration to
TeamCode, to override conflicting library configurations, or you will need to
add the offending configurations to a list, and return it via
`getPrioritisedOver` function, which will enforce priorities.

If `getPrioritisedOver` causes any cycles, both will be dropped from usage.

Keep an eye out for future use in Dairy, especially for automatically changing
configurations for tests!
