MvcComponent extends Component { @Override public Component register(@NotNull Provider provider) throws ProviderConflictException { super.register(provider); provider.registerCreationListener(new Provider.CreationListener() { @Override public void onCreated(Provider provider, Object instance) { if (instance instanceof Bean) { final Bean bean = (Bean) instance; bean.onCreated(); logger.trace("+++Bean created - '{}'.", provider.type().getSimpleName()); } } }); return this; } MvcComponent(String name);  MvcComponent(String name, boolean enableCache); @SuppressWarnings("unchecked") @Override Provider<T> findProvider(final Class<T> type, Annotation qualifier); @Override Component register(@NotNull Provider provider);  }
@Test public void test_injection_with_different_component_for_different_scoping() throws Exception{ MvcComponent componentWithCache = new MvcComponent("SmallLender"); componentWithCache.register(new Object(){ @Provides public Car car() { return new Car(); } }); Mvc.graph().getRootComponent().attach(componentWithCache); Tourist tourist1 = new Tourist(); Mvc.graph().inject(tourist1); Tourist tourist2 = new Tourist(); Mvc.graph().inject(tourist2); Assert.assertTrue(tourist1.car == tourist2.car); Mvc.graph().getRootComponent().detach(componentWithCache); boolean useScopeCache = false; MvcComponent componentWithoutCache = new MvcComponent("BigLender", useScopeCache); componentWithoutCache.register(new Object(){ @Provides public Car car() { return new Car(); } }); Mvc.graph().getRootComponent().attach(componentWithoutCache); Tourist tourist3 = new Tourist(); Mvc.graph().inject(tourist3); Tourist tourist4 = new Tourist(); Mvc.graph().inject(tourist4); Assert.assertTrue(tourist3.car != tourist4.car); }