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

Element of a good table (Ref: Database design mere mortals by Michael J. Hernandez)

  Elements of the Ideal Table: It represents a single subject, which can be an object or event that reduces the risk of potential data integ...