Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Guice decouple #13

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<modules>
<module>tef-core</module>
<module>tef-impl</module>
<module>tef-guice-bridge</module>
</modules>

<build>
Expand Down Expand Up @@ -107,23 +108,37 @@
</build>

<properties>
<revision>0.1.5</revision>
<guava.version>19.0</guava.version>
<guice.version>4.2.3</guice.version>
<revision>1.0.0</revision>
<guava.version>32.1.1-jre</guava.version>
<junit.version>4.13.2</junit.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public class DataAdapterKey<T> {

// The name of the data being emitted. Its allowed for the name to be empty (which is the default behavior) .
// The name of the data being emitted. It's allowed for the name to be empty (which is the default behavior) .
private final String name;
private final Class<T> resultClass;

Expand Down
8 changes: 4 additions & 4 deletions tef-core/src/main/java/flipkart/tef/bizlogics/TefContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package flipkart.tef.bizlogics;

import com.google.inject.Injector;
import flipkart.tef.interfaces.BizlogicInstanceProvider;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -32,11 +32,11 @@ public class TefContext {
// This map is to be used by clients to stash request level context info.
// This will be made available to bizlogics
private final Map<String, Object> extensions;
private final Injector injector;
private final BizlogicInstanceProvider injector;
private final Consumer<Throwable> exceptionLogger;


public TefContext(Map<String, Object> additionalContext, Injector injector, Consumer<Throwable> exceptionLogger) {
public TefContext(Map<String, Object> additionalContext, BizlogicInstanceProvider injector, Consumer<Throwable> exceptionLogger) {
this.extensions = new HashMap<>(additionalContext);
this.injector = injector;
this.exceptionLogger = exceptionLogger;
Expand All @@ -46,7 +46,7 @@ public <T> T getAdditionalContext(String key, Class<T> type) {
return type.cast(extensions.get(key));
}

public Injector getInjector() {
public BizlogicInstanceProvider getInjector() {
return injector;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package flipkart.tef.execution;
package flipkart.tef.exception;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@
* limitations under the License.
*/

package flipkart.tef;

import com.google.inject.AbstractModule;
import flipkart.tef.execution.DataInjector;
import flipkart.tef.execution.DefaultDataInjector;
package flipkart.tef.interfaces;

/**
* This class contains guice binding relevant for tef.
*
* Date: 01/07/21
* This interface is intended to expose methods that can help the flow executor eliminate its
* dependency on concrete implementations of DI (like google guice).
* <p>
* Flow Executor needs instances of Bizlogic during execution and this interface is queried for those instances.
* Clients can stub this with the `Injector` in guice or a similar implementation
* <p>
* Date: 16/07/23
*/
public class TefGuiceModule extends AbstractModule {
public interface BizlogicInstanceProvider {

@Override
protected void configure() {
bind(DataInjector.class).to(DefaultDataInjector.class);
}
<T> T getInstance(Class<T> var1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* limitations under the License.
*/

package flipkart.tef.execution;
package flipkart.tef.interfaces;

import flipkart.tef.exception.DataDependencyException;
import flipkart.tef.exception.TefExecutionException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package flipkart.tef.execution;
package flipkart.tef.interfaces;

import flipkart.tef.exception.TefExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package flipkart.tef.execution;
package flipkart.tef.interfaces;

import flipkart.tef.bizlogics.DataAdapterResult;

Expand Down
21 changes: 21 additions & 0 deletions tef-guice-bridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Tef Guice Bridge

The objective of this module is to use Guice's Dependency Injection techniques to inject data available within tef.

While Guice uses `@Inject` to inject any arbitrary dependency in fields or methods, TEF uses `@InjectData`
to inject data that is emitted from data adapters, to stitch the data dependency. For classes that are using both Guice
and TEF can leverage this module to use `@Inject` instead of `@InjectData` to inject data objects as well.

Please note that this data injection is outside the Flow Graph Execution and dependency checks are not performed. i.e.
Use Guice bridge on classes that are not part of simple flow.

A class has to add the annotation `@TefRequestScoped` if it wants to leverage this capability.

### Usage Instructions

1. Install the Guice Module `GuiceBridgeModule`
2. Mark the class with `@TefRequestScoped` wherever required
3. Use `@Inject` for data objects if they are being emitted via Data Adapters from Simple Flow
4. Use them anywhere in code without propagating it throughout.
5. Dependency Checks will not be performed on the data being injected. If the relevant DataAdapter has not been executed
yet, a null injection will be made.
47 changes: 47 additions & 0 deletions tef-guice-bridge/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~Copyright [2024] [The Original Author]
~
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>tef</artifactId>
<groupId>flipkart.tef</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>tef-guice-bridge</artifactId>

<properties>
<guice.version>5.1.0</guice.version>
</properties>

<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
</dependency>

<dependency>
<groupId>flipkart.tef</groupId>
<version>${revision}</version>
<artifactId>tef-core</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
*Copyright [2024] [The Original Author]
*
* 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.
*/

package flipkart.tef.guicebridge;

import com.google.inject.AbstractModule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
/*
*Copyright [2024] [The Original Author]
*
* 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.
*/

package flipkart.tef.guicebridge;

import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.MembersInjector;
import flipkart.tef.exception.TefExecutionException;
import flipkart.tef.execution.InjectableValueProvider;
import flipkart.tef.interfaces.InjectableValueProvider;

import java.lang.reflect.Field;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
*Copyright [2024] [The Original Author]
*
* 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.
*/

package flipkart.tef.guicebridge;

import com.google.inject.TypeLiteral;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
/*
*Copyright [2024] [The Original Author]
*
* 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.
*/

package flipkart.tef.guicebridge;

import com.google.common.base.Preconditions;
import com.google.inject.Key;
import com.google.inject.Provider;
import com.google.inject.Scope;
import flipkart.tef.execution.InjectableValueProvider;
import flipkart.tef.interfaces.InjectableValueProvider;

/**
* Custom guice scope (request-scoped) that injects an instance of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
*Copyright [2024] [The Original Author]
*
* 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.
*/

package flipkart.tef.guicebridge;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
*Copyright [2024] [The Original Author]
*
* 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.
*/

package flipkart.tef.guicebridge;

import com.google.inject.TypeLiteral;
Expand Down
Loading
Loading