/** * Install bindings for scope. */ private void installBindingForScope() { //it's always possible to get access to the scope that contains an injected object. installBoundProvider(Scope.class, null, new InternalProviderImpl<>(this), false); }
public T get(Scope scope) { return super.get(this.scope); } }
private <T> InternalProviderImpl<T> createInternalProvider(Scope scope, Class<?> factoryKeyClass, boolean isProviderClass, boolean isCreatingInstancesInScope, boolean isCreatingSingletonInScope, boolean isProvidingInstancesInScope) { if (isCreatingInstancesInScope) { return new ScopedProviderImpl<>(scope, factoryKeyClass, isProviderClass, isCreatingSingletonInScope, isProvidingInstancesInScope); } else { return new InternalProviderImpl<>(factoryKeyClass, isProviderClass, isCreatingSingletonInScope, isProvidingInstancesInScope); } }
@Override public <T> T getInstance(Class<T> clazz, String name) { crashIfClosed(); ConfigurationHolder.configuration.checkCyclesStart(clazz, name); T t; try { t = lookupProvider(clazz, name).get(this); } finally { ConfigurationHolder.configuration.checkCyclesEnd(clazz, name); } return t; }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenProviderFactoryIsNull() { //GIVEN //WHEN new InternalProviderImpl((Factory<Provider<String>>) null, true); //THEN fail("Should throw an exception"); }
public T get(Scope scope) { return super.get(this.scope); } }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenProviderInstanceIsNull() { //GIVEN //WHEN new InternalProviderImpl((Provider<String>) null, false); //THEN fail("Should throw an exception"); }
public T get(Scope scope) { return super.get(this.scope); } }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenProviderFactoryClassIsNull() { //GIVEN //WHEN new InternalProviderImpl((Class) null, true, false, false); //THEN fail("Should throw an exception"); }
@Override public T get() { //the first test avoids accessing a volatile when not needed if (isLazy && instance != null) { return instance; } //ensure both sync for DSL //and sync around provider //so that dev's providers don't deal with concurrency synchronized (this) { if (isLazy) { //DCL if (instance == null) { instance = providerInstance.get(scope); //gc providerInstance = null; } return instance; } return providerInstance.get(scope); } } }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenInstanceIsNull() { //GIVEN //WHEN new InternalProviderImpl((String) null); //THEN fail("Should throw an exception"); }
@Override public <T> T getInstance(Class<T> clazz, String name) { Configuration.instance.checkCyclesStart(clazz); T t = lookupProvider(clazz, name).get(this); Configuration.instance.checkCyclesEnd(clazz); return t; }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenFactoryIsNull() { //GIVEN //WHEN new InternalProviderImpl((Factory<String>) null, false); //THEN fail("Should throw an exception"); }
@Override public <T> T getInstance(Class<T> clazz) { Configuration.instance.checkCyclesStart(clazz); T t = lookupProvider(clazz, null).get(this); Configuration.instance.checkCyclesEnd(clazz); return t; }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenFactoryClassIsNull() { //GIVEN //WHEN new InternalProviderImpl((Class) null, false, false, false); //THEN fail("Should throw an exception"); }
@Override public <T> T getInstance(Class<T> clazz, String name) { crashIfClosed(); ConfigurationHolder.configuration.checkCyclesStart(clazz, name); T t; try { t = lookupProvider(clazz, name).get(this); } finally { ConfigurationHolder.configuration.checkCyclesEnd(clazz, name); } return t; }
} else { final InternalProviderImpl<T> newProvider = new InternalProviderImpl<>(factory, false);
false); case INSTANCE: return new InternalProviderImpl<>(binding.getInstance()); case PROVIDER_INSTANCE: return new InternalProviderImpl<>(binding.getProviderInstance(), binding.isProvidingSingletonInScope()); case PROVIDER_CLASS: return createInternalProvider(this,
/** * Install bindings for scope. */ private void installBindingForScope() { //it's always possible to get access to the scope that contains an injected object. installBoundProvider(Scope.class, null, new InternalProviderImpl<>(this), false); }
private <T> InternalProviderImpl<T> createInternalProvider(Scope scope, Class<?> factoryKeyClass, boolean isProviderClass, boolean isScoped) { if (isScoped) { return new ScopedProviderImpl<>(scope, factoryKeyClass, isProviderClass); } else { return new InternalProviderImpl<>(factoryKeyClass, isProviderClass); } }