All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.datakernel.di.core.BindingSet Maven / Gradle / Ivy

Go to download

DataKernel has an extremely lightweight DI with ground-breaking design principles. It supports nested scopes, singletons, object factories, modules and plugins which allow to transform graph of dependencies at startup time without any reflection.

The newest version!
package io.datakernel.di.core;

import io.datakernel.di.module.ModuleBuilderBinder;

import java.util.HashSet;
import java.util.Set;

/**
 * This class represents a set of bindings for the same key.
 * It also contains the {@link BindingType} - it is mostly used for plain binds with extra calls,
 * such as {@link ModuleBuilderBinder#asTransient transient} or {@link ModuleBuilderBinder#asEager eager}.
 * 

* Note that one of the bindings itself may still be transient while the type of the set is {@link BindingType#COMMON COMMON}, * this case should be handled properly (e.g. {@link Multibinder#toSet toSet()} multibinder is transient if at least one of its peers is transient). */ public final class BindingSet { private final Set> bindings; private BindingType type; public BindingSet(Set> bindings, BindingType type) { this.bindings = bindings; this.type = type; } public Set> getBindings() { return bindings; } public BindingType getType() { return type; } public void setType(BindingType type) { this.type = type; } @SuppressWarnings("unchecked") public static BindingSet merge(Key key, BindingSet first, BindingSet second) { if (first.type != second.type) { throw new DIException("Two binding sets bound with different types for key " + key.getDisplayString()); } Set> set = new HashSet<>(); set.addAll(first.bindings); set.addAll(second.bindings); return new BindingSet(set, first.type); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy