# Parameters

It is possible to define container parameters that will be injected into its beans after the wiring and before the init method invocation. Parameter is defined with the `String` name and value of any type.

By default, parameters are injected before init method invocation. In some cases, some init methods has to be invoked before setting the parameters. That is done by setting the `firstOff` element of `@PetiteInitMethod`, to indicate that init method has to be invoked before parameters injection.

### Convention

Parameters are bind to the container using the convention: parameter name starts with the bean name. Example:

```java
PetiteContainer pc = new PetiteContainer();
pc.registerBean(Foo.class);                 // registered as "foo"
pc.defineParameter("foo.name", "FOONAME");
...
Foo foo = (Foo) pc.getBean("foo");
foo.getName();                              // "FOONAME"
```

### Parameter References

Sometimes, one parameter has to be injected in several different beans. In order to prevent repeating, it is possible to use parameter references. Parameter reference is a parameter name surrounded with `${}` that points to some other parameter. It can occur anywhere in the value string. Nested references are supported as well. Example:

```java
    PetiteContainer pc = new PetiteContainer();
    pc.registerBean(Foo.class);                     // registered as "foo"
    pc.defineParameter("foo.name", "${name}");      // ref -> name
    pc.defineParameter("name", "${name${num}}");    // ref -> name2
    pc.defineParameter("num", "2");
    pc.defineParameter("name2", "FOONAME");

    ...
    Foo foo = (Foo) pc.getBean("foo");
    foo.getName();                                  // "FOONAME"
```

Resolving references is optional and, by default, is turned on.

*Petite* container doesn't detect circular dependencies when resolving parameters. {: .attn}

References can be escaped with single `\` character, while `\\` removes escaping effect and are resolved to single backslash.

References are resolved late, on their first injection.

### Loading from Map

It is possible to load parameters from any `Map` implementation, such as `Properties`.

```java
    Properties myProperties = ....;
    pc.defineParameters(myProperties);
```

### Loading from Props

It is possible to load parameters from **Props**, too:

```java
    Props myProps = ....;
    pc.defineParameters(myProps);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://petite.jodd.org/parameters.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
