Sunday, September 12, 2021

DI(dependency injection) using example

 Suppose we have a controller ,which accepts the request  and will response , but it depends on business layer.

@Controller

public class TodoController{

@Autowired

TodoBusinessService todoBusinessService;

}

TodoBusinessService depends to another dependency to fetch data from the database,

@Component

public class TodoBusinessService{

@Autowired

TodoDataService todoDataService;

}

now TodoDataService need to fire a query to fetch data from the database .So it depends on JdbcTemplate.

@Component

public class TodoDataService {

@Autowired

JdbcTemplate jdbcTemplate;

}

No comments:

Post a Comment

Javascript module

JavaScript Modules (ES6) let you split code into multiple files and reuse code cleanly. Main keywords: export → make something available...