# Configuration

{% hint style="warning" %}
The API is likely to change as Doddle stabilises
{% endhint %}

### Configuring

To create a new client configuration, we need use the builder

```java
import dev.doddle.core.DoddleConfigurationBuilder;
final DoddleConfigurationBuilder builder = new DoddleConfigurationBuilder();
```

#### Storage

Configure Doddle to use your chosen storage provider. See the previous chapter about storage providers.

```java
builder.storage(storageProvider);
```

#### Packages

This is where Doddle will look for class methods annotated with the `@Task` annotation.

For example, if you have a task defined in `com.example.tasks.OrderTask`s then set this value to `com.example.tasks.`

```java
builder.packages("com.examples.tasks");
```

#### Resolver

Doddle needs to know how to get an instance or create an instance of a class that has a method annotated with the `@Task` annotation.

For example, let's say we have the following service with a task

```java
public class OrderService {
    private final CustomerService customerService;
    
    OrderManager(CustomerService customerService) {
        this.customerService = customerService;
    }
    
    @Task
    public void process() {
    
    }
}
```

Doddle does not know how to instantiate this class - it has no idea how to get an instance of the `CustomerService` class.  Let's solve that by creating a simple resolver:

```java
builder.resolver(new TaskDependencyResolver() {
    @Override
    public <T> T resolve(Class<T> clazz) {
        if (clazz == OrderService.class) {
            return clazz.cast(new OrderService(new CustomerService()));
        }
        return null;
    }
});
```

{% hint style="info" %}
This is just a simple example. You would normally use a dependency injection container such as a [Guice](https://github.com/google/guice) or [Spring IoC](https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/beans.html) to get instances of your classes!
{% endhint %}

Great, Doddle now knows how to create the objects containing the task methods!

#### Scheduling

The scheduler is used to find jobs that are ready to be processed.

```java
builder.scheduling(options -> {
    options.interval("1s")
           .delay("5000ms")
    return options;
});
```

| Parameter | Description                                                             | Input                                                                  |
| --------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| interval  | <p>How often to check for jobs that are ready to be processed. <br></p> | Valid units are ms (milliseconds), s (seconds), m (minutes), h (hours) |
| delay     | The time to wait before checking after the scheduler is started.        | Valid units are ms (milliseconds), s (seconds), m (minutes), h (hours) |

### Creating the client

#### Build the configuration

```java
DoddleConfiguration configuration = builder.build();
```

#### Create the client

```java
DoddleClientFactory factory = new DoddleClientFactory();
DoddleClient client = factory.createClient(configuration);
```

Great, we now have a client!&#x20;
