22.09.05 10:40 작성
·
258
0
(1)
public class MemberServiceImpl implements MemberService{
private final MemberRepository memberRepository;
public MemberServiceImpl(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}
@Override
public void join(Member member) {
memberRepository.save(member);
}
@Override
public Member findMember(Long memberId) {
return memberRepository.findById(memberId);
}
}
(2)
public class AppConfig {
public MemberService memberService(){
return new MemberServiceImpl(memberRepository());
}
public MemberRepository memberRepository() {
return new MemoryMemberRepository();
}
}
두개의 코드가 있을때 Appconfig에 의해 인스턴스가 생성되고, MemberServiceImpl에 들어간다고 강사님께서 설명해주셧습니다.
이때 MemberServiceImpl에서 Appconfig 객체를 생성한다던지, 메서드를 호출하는 코드가 없는데 자동으로 주입되는 이유가 궁금합니다. 감사합니다.