
com.github.nill14.utils.init.scope.AbstractThreadScope Maven / Gradle / Ivy
The newest version!
package com.github.nill14.utils.init.scope;
import javax.inject.Provider;
import com.github.nill14.utils.init.api.BindingKey;
import com.github.nill14.utils.init.api.IScope;
import com.github.nill14.utils.init.api.IScopeContext;
public abstract class AbstractThreadScope implements IScope {
private final ThreadLocal threadLocal = ThreadLocal.withInitial(ScopeContext::new);
@Override
public Provider scope(BindingKey type, Provider unscoped, IScopeContext scopeContext) {
return threadLocal.get().scope(type, unscoped);
}
protected ScopeContext get() {
return threadLocal.get();
}
protected void set(ScopeContext context) {
threadLocal.set(context);
}
protected void remove() {
threadLocal.remove();
}
protected Provider outOfScopeProvider() {
return () -> null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy