adennie/fb-android-dagger

语言: Java

git: https://github.com/adennie/fb-android-dagger

一组辅助类,用于将dagger 1与Android组件一起使用,例如Applications,Activities,Fragments,Broad ...
A set of helper classes for using dagger 1 with Android components such as Applications, Activities, Fragments, Broad…
README.md (中文)

FB-Android的匕首

A set of helper classes for using 匕首 with Android components such as
Applications, Activities, Fragments, BroadcastReceivers, and Services.

Maven用户:

<dependency>
   <groupId>com.fizz-buzz</groupId>
   <artifactId>fb-android-dagger</artifactId>
   <version>1.0.6</version>
</dependency>

Note: this project's POM specifies dependencies for the Android SDK and the support v4 library using the
group IDs, artifact IDs, and version numbers created by the Maven Android SDK Deployer, as opposed to the ones in Maven Central, which contains
artifacts that are unofficial and out of date. If you want to use the ones in Maven Central anyway, just update
those dependencies in the POM.

概观

fb-android-dagger提供了一组在Android应用程序中使用dagger的基类。它遵循Square的示例应用程序所示的约定,其中基类调用getModules()来收集其子类需要成为图的一部分的模块集,然后从这些模块创建对象图并注入其自身。

提供以下类,每个类在括号中指示的方法中实现此技术:

  • InjectingApplication (onCreate)
  • InjectingBroadcastReceiver (onReceive)
  • InjectingAppWidgetProvider (onReceive)
  • InjectingService (onCreate)
  • InjectingActivity (onCreate)
  • InjectingActionBarActivity (onCreate)
  • InjectingFragmentActivity (onCreate)
  • InjectingPreferenceActivity (onCreate)
  • InjectingFragment (onAttach)
  • InjectingListFragment (onAttach)
  • InjectingDialogFragment (onAttach)

图表

InjectingApplication creates an application-scope graph.

InjectingBroadcastReciever, InjectingAppWidgetProvider, InjectingService, and the various Injecting...Activity classes each extend the application-scope graph with their own module(s), resulting in a graph scoped to their own component.

The various Injecting...Fragment classes extend their corresponding activity's graph.

模块

Each component type has an associated module:
- InjectingActivityModule
- InjectingServiceModule
- InjectingBroadcastRecieverModule
- InjectingActivityModule
- InjectingFragmentModule

The last two are shared by the Injecting...Activity classes and the Injecting...Fragment classes, respectively. These modules define provider methods which enable injection of objects relevant to their component type. They all have a provider that returns the component itself in the form of an Injector interface:

public interface Injector {
    public ObjectGraph getObjectGraph();
    public void inject(Object target);
}

各种模块中定义的限定符注释允许访问特定组件的注入器:

class Foo1 {
    @Inject @Application Injector appInjector;
    @Inject @Activity Injector activityInjector;
    @Inject @Fragment Injector fragInjector;
    //...
}

应用程序和活动上下文同样可访问:

class Foo2 {
    @Inject @Application Context appContext;
    @Inject @Activity Context activityContext;
    // ...
}

......以及键入的组件本身:

class Foo3 {
    @Inject Application theApp;
    @Inject Activity myActivity;
    @Inject Fragment myFragment;
    // ...
}

由开发

Andy Dennie - Andy@fizz-不知足.com

执照

版权所有2014 Fizz Buzz LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

HTTP://呜呜呜.Apache.org/licenses/license-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

fb-android-dagger

A set of helper classes for using dagger with Android components such as
Applications, Activities, Fragments, BroadcastReceivers, and Services.

Maven users:

<dependency>
   <groupId>com.fizz-buzz</groupId>
   <artifactId>fb-android-dagger</artifactId>
   <version>1.0.6</version>
</dependency>

Note: this project's POM specifies dependencies for the Android SDK and the support v4 library using the
group IDs, artifact IDs, and version numbers created by the Maven Android SDK Deployer, as opposed to the ones in Maven Central, which contains
artifacts that are unofficial and out of date. If you want to use the ones in Maven Central anyway, just update
those dependencies in the POM.

Overview

fb-android-dagger provides a set of base classes for using dagger in Android applications. It follows a convention exemplified by Square's sample application, whereby a base class calls getModules() to gather the set of modules that its subclass(es) need to be part of the graph, then creates an object graph from those modules and injects itself.

The following classes are provided, each implementing this technique in the method indicated in parentheses:

  • InjectingApplication (onCreate)
  • InjectingBroadcastReceiver (onReceive)
  • InjectingAppWidgetProvider (onReceive)
  • InjectingService (onCreate)
  • InjectingActivity (onCreate)
  • InjectingActionBarActivity (onCreate)
  • InjectingFragmentActivity (onCreate)
  • InjectingPreferenceActivity (onCreate)
  • InjectingFragment (onAttach)
  • InjectingListFragment (onAttach)
  • InjectingDialogFragment (onAttach)

The graphs

InjectingApplication creates an application-scope graph.

InjectingBroadcastReciever, InjectingAppWidgetProvider, InjectingService, and the various Injecting...Activity classes each extend the application-scope graph with their own module(s), resulting in a graph scoped to their own component.

The various Injecting...Fragment classes extend their corresponding activity's graph.

Modules

Each component type has an associated module:
- InjectingActivityModule
- InjectingServiceModule
- InjectingBroadcastRecieverModule
- InjectingActivityModule
- InjectingFragmentModule

The last two are shared by the Injecting...Activity classes and the Injecting...Fragment classes, respectively. These modules define provider methods which enable injection of objects relevant to their component type. They all have a provider that returns the component itself in the form of an Injector interface:

public interface Injector {
    public ObjectGraph getObjectGraph();
    public void inject(Object target);
}

Qualifier annotations defined in the various modules allow for specific components' injectors to be accessed:

class Foo1 {
    @Inject @Application Injector appInjector;
    @Inject @Activity Injector activityInjector;
    @Inject @Fragment Injector fragInjector;
    //...
}

Application and Activity Contexts are similarly accessible:

class Foo2 {
    @Inject @Application Context appContext;
    @Inject @Activity Context activityContext;
    // ...
}

...as are the typed components themselves:

class Foo3 {
    @Inject Application theApp;
    @Inject Activity myActivity;
    @Inject Fragment myFragment;
    // ...
}

Developed by

Andy Dennie - andy@fizz-buzz.com

License

Copyright 2014 Fizz Buzz LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.