Open Mahoolya opened 1 year ago
Dependency injection or inversion of control (IOC) This pattern is connected with bean injection. So we have Controller class, where we use some service. Service uses some repository. We add before beans @Autowired annotation and Spring injects all necessary beans.
Model View Controller Pattern The goal of this pattern is to separate program into 3 layers:
Singleton pattern By default beans have singleton scope. So, creating HotelService (from the app) and using annotation @RequriedArgsConstructor(= @Autowired by field) we don't create two objects, only one, as in Singleton Pattern documentation. To change bean scope from singleton to prototype we can use @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) annotation => we will get two different objects.