java - Dependency Injection And Fluent Design -


say have spring component below dependencies constructor injected (builder singleton):

@component public class housebuilder{       private windowmaker windowmaker;      private doormaker doormaker;      private roofmaker roofmaker;       @autowired      public housebuilder(windowsmaker wm, doormaker dm, roofmaker rm){             this.windowmaker = wm;             this.doormaker = dm;             this.roofmaker = rm;      }       //other methods omitted brevity  } 

however house requires called "foundation" should passed in through constructor or set before making house begins , foundation not spring bean. i'd use builder pattern below unsure how spring. below after except want use spring:

foundation foundation = new foundation();  housebuilder hb = new housebuilder(foundation) .windowmaker(args) .doormaker(args) .roofmaker(args); 

any advice appreciated.

spring dependency injection , fluent builders not designed work together.

the first way set dependencies of object in "automatic" way via annotation or configuration.
while second way clients of class specify how object should build.

automatic dependency injection , declarative construction 2 distinct ways create objects.

as side note, spring dependency injection constructor brings 2 major fluent builder benefits : no more cumbersome constructor call injection performed container , object may immutable no setter required.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -