public abstract class Registries extends Object
registries
.Modifier and Type | Method and Description |
---|---|
static Registry |
join(Registry parent,
Registry child)
Joins the given registries into a new registry.
|
static RegistryBuilder |
registry()
Creates a new
registry builder . |
static <T> Registry |
registry(Class<? super T> publicType,
T implementation)
Creates a single entry registry, using
RegistryBuilder.add(Class, Object) . |
static <T> Registry |
registry(Class<T> publicType,
Factory<? extends T> factory)
Creates a single lazily created entry registry, using
RegistryBuilder.add(Class, Factory) . |
static Registry |
registry(Object object)
Creates a single entry registry, using
RegistryBuilder.add(Object) . |
public static <T> Registry registry(Class<? super T> publicType, T implementation)
RegistryBuilder.add(Class, Object)
.T
- the public type of the entrypublicType
- the public type of the entryimplementation
- the entry objectRegistryBuilder.add(Class, Object)
public static <T> Registry registry(Class<T> publicType, Factory<? extends T> factory)
RegistryBuilder.add(Class, Factory)
.T
- the public type of the entrypublicType
- the public type of the entryfactory
- the factory for the objectRegistryBuilder.add(Class, Factory)
public static Registry registry(Object object)
RegistryBuilder.add(Object)
.object
- the entry objectRegistryBuilder.add(java.lang.Object)
public static RegistryBuilder registry()
registry builder
.RegistryBuilder
public static Registry join(Registry parent, Registry child)
The returned registry is effectively the union of the two registries, with the child
taking precedence.
This means that child entries are effectively “returned first”.
import ratpack.registry.Registry; import static ratpack.registry.Registries.registry; import static ratpack.registry.Registries.join; public interface Thing { String getName() } public class ThingImpl implements Thing { private final String name public ThingImpl(String name) { this.name = name; } public String getName() { return name; } } Registry child = registry().add(Thing.class, new ThingImpl("child-1")).add(Thing.class, new ThingImpl("child-2")).build(); Registry parent = registry().add(Thing.class, new ThingImpl("parent-1")).add(Thing.class, new ThingImpl("parent-2")).build(); Registry joined = join(parent, child); assert joined.get(Thing.class).getName() == "child-1"; List<Thing> all = joined.getAll(Thing.class); assert all.get(0).getName() == "child-1"; assert all.get(1).getName() == "child-2"; assert all.get(2).getName() == "parent-1"; assert all.get(3).getName() == "parent-2";
parent
- the parent registrychild
- the child registry