summaryrefslogtreecommitdiffstats
path: root/component/src/main
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2021-04-13 12:28:42 +0200
committerGitHub <noreply@github.com>2021-04-13 12:28:42 +0200
commitc752d3e4bcc1946358ccdee716f4141bf87748df (patch)
treebf3ee4c16006437ac79b893cc09e1e05c8714339 /component/src/main
parent86097c6b1e4a59cef5b9dfcdec021213520b51ac (diff)
parentbbff5a9bb8854d7100b4981af9aa226d74ae0227 (diff)
Merge pull request #17380 from vespa-engine/gjoranv/merge-di-into-core_2
Gjoranv/merge di into core 2 [run-systemtest]
Diffstat (limited to 'component/src/main')
-rw-r--r--component/src/main/java/com/yahoo/container/di/componentgraph/Provider.java26
-rw-r--r--component/src/main/java/com/yahoo/container/di/componentgraph/package-info.java12
2 files changed, 38 insertions, 0 deletions
diff --git a/component/src/main/java/com/yahoo/container/di/componentgraph/Provider.java b/component/src/main/java/com/yahoo/container/di/componentgraph/Provider.java
new file mode 100644
index 00000000000..3fd3195e5dd
--- /dev/null
+++ b/component/src/main/java/com/yahoo/container/di/componentgraph/Provider.java
@@ -0,0 +1,26 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.di.componentgraph;
+
+import com.yahoo.component.Deconstructable;
+
+/**
+ * <p>Provides a component of the parameter type T.
+ * If (and only if) dependency injection does not have a component of type T,
+ * it will request one from the Provider providing type T.</p>
+ *
+ * <p>Providers are useful in these situations:</p>
+ * <ul>
+ * <li>Some code is needed to create the component instance in question.</li>
+ * <li>The component creates resources that must be deconstructed.</li>
+ * <li>A fallback component should be provided in case the application (or system)
+ * does not provide a component instance.</li>
+ * </ul>
+ *
+ * @author Tony Vaagenes
+ * @author gjoranv
+ */
+public interface Provider<T> extends Deconstructable {
+
+ T get();
+
+}
diff --git a/component/src/main/java/com/yahoo/container/di/componentgraph/package-info.java b/component/src/main/java/com/yahoo/container/di/componentgraph/package-info.java
new file mode 100644
index 00000000000..054abe9cff9
--- /dev/null
+++ b/component/src/main/java/com/yahoo/container/di/componentgraph/package-info.java
@@ -0,0 +1,12 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+/**
+ * Note that this package also exists in another Vespa module, for historical
+ * reasons. All Java classes should be kept in this module, and the other
+ * module's package should remain empty.
+ */
+@ExportPackage
+@PublicApi
+package com.yahoo.container.di.componentgraph;
+
+import com.yahoo.api.annotations.PublicApi;
+import com.yahoo.osgi.annotation.ExportPackage;