Coder Social home page Coder Social logo

daviddev16 / dependency4j Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 0.0 138 KB

🌱 A lightweight Java library designed for Inverse of Control and Dependency Injection management

License: MIT License

Java 100.00%
dependency-injection dependency-inversion dependency-manager java inverse-of-control

dependency4j's Introduction

Olá 👋 Me Chamo David Duarte!

Sou um desenvolvedor de Software

Sou autodidata e muito interessado nas tecnologias de comunicação e transmissão de dados e linguagens de programação; Com um desejo muito grande de inovar e trazer ferramentas e softwares que sejam realmente utéis no dia-a-dia; Atualmente estudo ciência da computação no Centro Universitário Serra dos Órgãos (UNIFESO); Estudo para me tornar um desenvolvedor de Software Full Stack e Web, focando no Backend e Devops. 🛠️

Coding

  • 🔭 Atualmente trabalho na Alterdata Software como técnico de Suporte Shop;

  • 🌱 Atualmente aprendendo Devops, Delphi e Gerenciamento de Redes;

  • 👨‍💻 Minha trajetória e projetos podem ser vistos em meu portifólio;

  • ❤️ Vamos conversar sobre Java, Delphi, Csharp e PostgreSQL;

  • 📫 Meu contato é [email protected];

Contatos:

daviddev16 daviddev16


Algumas ferramentas e linguagens que já utilizei ou utilizo.


Não foi possível listar todas!

Atividade

Daviddev16's Graph

dependency4j's People

Contributors

daviddev16 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dependency4j's Issues

Virtual Instance recursive problem

Expected Behavior

Adding a virtual method inside a class that uses the virtual method return type, the application should be able to identify a recursive problem and throw a proper exception.

Actual Behavior

A Stack overflow is thrown

	at io.github.dependency4j.DependencyManager.instantiateWithInjection(DependencyManager.java:315)
	at io.github.dependency4j.DependencyManager.instantiateWithInjection(DependencyManager.java:383)
	at io.github.dependency4j.DependencyManager.fetchOrCreateObjectFromClassType(DependencyManager.java:577)
	at io.github.dependency4j.DependencyManager.lambda$createObjectsFromParameters$2(DependencyManager.java:506)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at io.github.dependency4j.DependencyManager.createObjectsFromParameters(DependencyManager.java:510)
	at io.github.dependency4j.DependencyManager.createInstanceWithAnnotatedConstructor(DependencyManager.java:603)
	at io.github.dependency4j.DependencyManager.handleSingletonClassInstantiation(DependencyManager.java:412)
	at io.github.dependency4j.DependencyManager.handleConcreteSingletonClassInstantiation(DependencyManager.java:440)
	at io.github.dependency4j.DependencyManager.instantiateWithInjection(DependencyManager.java:318)
	at io.github.dependency4j.DependencyManager.instantiateWithInjection(DependencyManager.java:383)
	at io.github.dependency4j.DependencyManager.handleVirtualSingletonClassInstantiation(DependencyManager.java:469)
	at io.github.dependency4j.DependencyManager.instantiateWithInjection(DependencyManager.java:315)
	at io.github.dependency4j.DependencyManager.instantiateWithInjection(DependencyManager.java:383)
	at io.github.dependency4j.DependencyManager.fetchOrCreateObjectFromClassType(DependencyManager.java:577)
	at io.github.dependency4j.DependencyManager.lambda$createObjectsFromParameters$2(DependencyManager.java:506)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at io.github.dependency4j.DependencyManager.createObjectsFromParameters(DependencyManager.java:510)
	at io.github.dependency4j.DependencyManager.createInstanceWithAnnotatedConstructor(DependencyManager.java:603)
	at io.github.dependency4j.DependencyManager.handleSingletonClassInstantiation(DependencyManager.java:412)

Specifications

  • Version: 1.0.4
  • JDK: Eclipse Adoptium 17.0.8.101

Virtual Singleton Instances

Feature Request

Is your feature request related to a problem? Please describe.:
No

Describe the solution you'd like:
Virtual singleton instance is a way to enable a function-level singleton instance creation. The function will be annotated with @Virtual and it would behave as an instantiation of a class, storing its return value as a SingletonNode in the Dependency Search Tree.

Describe alternatives you've considered
Using a @Managed class would work.

Teachability, Documentation, Adoption, Migration Strategy
By querying the types, the virtual instances would behave like a class, the only change would be in the initialization of this SecretsManager type, which would be done by a method invocation.

@Virtual
SecretsManager virtualSecretsManager() {
  return SecretsManager
            .builder()
            .superSecretKey("123")
            .build();
}
@Test
void testVirtualSecretsManager() {
    SecretsManager secretsManager = dependencyManager.query(SecretsManager.class);
    assertEquals("123", secretsManager.getSuperSecretKey()); //must be successful
}

Annotation Composition

Feature Request

Is your feature request related to a problem? Please describe.:
No

Describe the solution you'd like:
Annotation Composition is a way to let the user create custom annotations aggregated with Dependency4J annotations. Let's suppose we have a Staging and Production environment, we would annotate all production classes with @Managed(strategy = @Strategy({"Production"})) and staging classes with @Managed(strategy = @Strategy({"Staging"})). But this is too repetitive, if we change the production strategy, we would have to change in all classes. With annotation composition, we can create an annotation: @ManagedInProduction annotated with @Managed(strategy = @Strategy({"Production"})) and only use @ManagedInProduction in our business classes.

Describe alternatives you've considered
Using a @Managed annotation with strategy set would work.

Teachability, Documentation, Adoption, Migration Strategy
This is an optional feature, users can still use @Managed in all classes.

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Managed(strategy = @Strategy("Production"))
public @interface ManagedInProduction { }
@ManagedInProduction
public class PostgreSQLRepository implements DbRepository {...}

Virtual Instance bug when using interface types as function return

Expected Behavior

When using an abstract/interface as a function return type, the type should be appended to the search tree and no exception should be thrown.

Actual Behavior

While using interfaces as return type:

@Virtual
public Encoder md5Enconder() {
  return new MD5Encoder();
}

DependencySearchTree#createTypeFamiliesInSearchTree throw an error:

Exception in thread "main" io.github.dependency4j.exception.InstallationFailedException: Package "com.example" installation failed.
	at io.github.dependency4j.DependencyManager.installPackage(DependencyManager.java:91)
	at io.github.dependency4j.DependencyManagerChainBuilder.installPackage(DependencyManagerChainBuilder.java:25)
	at com.example.Main.main(Main.java:26)
Caused by: java.lang.NullPointerException: Cannot invoke "Object.equals(Object)" because "superclassClassType" is null
	at io.github.dependency4j.DependencySearchTree.generateSuperclassPathSet(DependencySearchTree.java:287)
	at io.github.dependency4j.DependencySearchTree.createSuperclassTreeMapping(DependencySearchTree.java:256)
	at io.github.dependency4j.DependencySearchTree.createTypeFamiliesInSearchTree(DependencySearchTree.java:139)
	at io.github.dependency4j.DependencySearchTree.lambda$createVirtualSingletonsInSearchTree$0(DependencySearchTree.java:337)
	at io.github.dependency4j.util.ReflectionUtil.consumeAllVirtualMethodsFromClassType(ReflectionUtil.java:43)
	at io.github.dependency4j.DependencySearchTree.createVirtualSingletonsInSearchTree(DependencySearchTree.java:333)
	at io.github.dependency4j.DependencySearchTree.createTypeFamiliesInSearchTree(DependencySearchTree.java:144)
	at io.github.dependency4j.DependencySearchTree.createTypeFamiliesInSearchTree(DependencySearchTree.java:100)
	at io.github.dependency4j.DependencySearchTree.insert(DependencySearchTree.java:52)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at io.github.dependency4j.DependencyManager.installPackage(DependencyManager.java:87)
	... 2 more

Steps to Reproduce the Problem

  1. An example can be replicated by using interface as a return type.

Specifications

  • Version: 1.0.4
  • JDK: Eclipse Adoptium 17.0.8.101

Documentation of Classes

Documentation Request (javadocs)

  • Strategy.java
  • DependencyManager.java
  • DependencySearchTree.java
  • DependencyManagerChainBuilder.java
  • InstallationType.java
  • Managed.java
  • Pull.java
  • QueryOptions.java
  • ClassFinder.java
  • AnnotationTransformer.java
  • AbstractNode.java
  • BaseNode.java
  • JavaTypeNode.java
  • NodeType.java
  • RootNode.java
  • SingletonNode.java
  • Checks.java
  • D4JUtil.java
  • StrUtil.java
  • StateException.java
  • ScanFailedException.java
  • InstallationFailedException.java
  • ClassCreationFailedException.java
  • MemberInjectionFailedException.java
  • ReflectionStateException.java
  • QueryableProxy.java
  • Virtual.java
  • AnnotationDecomposer.java

DependencyManager creates 2 objects for the same class type.

Expected Behavior

query(...) method and @Pull injection should return a single unique instance of a class type.

Actual Behavior

While DependencyManager injects dependencies with install(), an instance of ProductService was duplicated and the system gives an unexpected behavior. After initializing a ProductService and registering a product on it, query method returned the duplicated instance of ProductService and unexpectedly the product could not be found.

image

Steps to Reproduce the Problem

  1. An example can be replicated by using constructor injection, consuming the dependency object and wait for the installation to complete.

Specifications

  • Version: 1.0
  • JDK: Eclipse Adoptium 17.0.8.101

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.