• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Dagger Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dagger.hilt.android.migration;
18 
19 import java.lang.annotation.ElementType;
20 import java.lang.annotation.Target;
21 
22 /**
23  * When used on a {@link dagger.hilt.android.HiltAndroidApp}-annotated application, this causes the
24  * application to no longer inject itself in onCreate and instead allows it to be injected at some
25  * other time.
26  *
27  * <p>When using this annotation, you can use {@link CustomInjection#inject} to inject the
28  * application class. Additionally, this annotation will also cause a method, {@code customInject}
29  * to be generated in the Hilt base class as well, that behaves the same as
30  * {@link CustomInjection#inject}. The method is available to users that extend the Hilt base class
31  * directly and don't use the Gradle plugin.
32  *
33  * <p> Example usage:
34  *
35  * <pre><code>
36  * {@literal @}CustomInject
37  * {@literal @}HiltAndroidApp(Application.class)
38  * public final class MyApplication extends Hilt_MyApplication {
39  *
40  *   {@literal @}Inject Foo foo;
41  *
42  *   {@literal @}Override
43  *   public void onCreate() {
44  *     // Injection would normally happen in this super.onCreate() call, but won't now because this
45  *     // is using CustomInject.
46  *     super.onCreate();
47  *     doSomethingBeforeInjection();
48  *     // This call now injects the fields in the Application, like the foo field above.
49  *     CustomInject.inject(this);
50  *   }
51  * }
52  * </code></pre>
53  */
54 @Target(ElementType.TYPE)
55 public @interface CustomInject {}
56