예제 #1
0
  /**
   * Finds or creates the scope for the given screen, honoring its optional {@link
   * WithModuleFactory} or {@link WithModule} annotation. Note that scopes are also created for
   * unannotated screens.
   */
  public MortarScope getScreenScope(
      Resources resources, MortarScope parentScope, final String name, final Object screen) {
    ModuleFactory moduleFactory = getModuleFactory(screen);
    Object[] childModule;
    if (moduleFactory != NO_FACTORY) {
      childModule = new Object[] {moduleFactory.createDaggerModule(resources, screen)};
    } else {
      // We need every screen to have a scope, so that anything it injects is scoped.  We need
      // this even if the screen doesn't declare a module, because Dagger allows injection of
      // objects that are annotated even if they don't appear in a module.
      childModule = new Object[0];
    }

    MortarScope childScope = parentScope.findChild(name);
    if (childScope == null) {
      childScope =
          parentScope
              .buildChild()
              .withService(
                  ObjectGraphService.SERVICE_NAME,
                  ObjectGraphService.create(parentScope, childModule))
              .build(name);
    }

    return childScope;
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   AppComponent app = DaggerService.getDaggerComponent(getApplicationContext());
   mActivityScope =
       MortarScope.buildChild(getApplicationContext())
           .withService(
               DaggerService.DAGGER_SERVICE,
               DaggerSettingsActivityComponent.builder().appComponent(app).build())
           .build(UUID.randomUUID().toString());
   super.onCreate(savedInstanceState);
 }
예제 #3
0
  public static Navigator create(
      MortarScope containerScope, StackableParceler parceler, Config config) {
    if (config == null) {
      config = new Config();
    }

    Preconditions.checkNotNull(containerScope, "Mortar scope for Navigator cannot be null");
    Preconditions.checkArgument(
        config.dontRestoreStackAfterKill || parceler != null,
        "StackableParceler for Navigator cannot be null");

    Navigator navigator = new Navigator(parceler, config);

    MortarScope scope =
        containerScope.buildChild().withService(SERVICE_NAME, navigator).build(SCOPE_NAME);
    scope.register(navigator);

    return navigator;
  }