Git Product home page Git Product logo

circular-dependencies's Introduction

circular-dependencies

The bean life-cycle as in an instantiation phase, it has three sub-phases to carry out dependency injections. The earliest one is through a constructor(sub-phase, i.e. instantiating bean), the latter one as a setter invoked, and the last chance(Initializer) for DI is through a postConstruct method. As two beans depend on each other(bi-directional association), one may use constructor DI and anther one use setter DI. This avoids the circular-dependency error(it looks like a deadlock), because making one wait a while to get another bean's reference.

image

The diagram shows a bean life-cycle, the middlebox presents the main phase, i.e. instantiation phase, in which there are three subphases we may define dependency injections. 1) Instantiate bean: constructor DI; 2) Setters called: Setter DI; 3) Initializer: @PostConstruct method called here.

Normally bean-factory can figure out a bean and its dependencies automatically, i.e. a bean graph. However, for a bi-directional relationship, which leads to a circular-dependency, the bean factory cannot figure out who should be cooked first, so it may cause an error, bla bla the dependent bean is not created yet. So, it needs to explicitly declare @DependOn a bean, which implements DI using a setter method.

circular-dependencies's People

Contributors

yichunzhao avatar

Watchers

 avatar  avatar

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.