IoC Container를 이용한 디자인

stylix의 이미지

요즘 IoC Container에 관해 공부하고 있습니다.
Integration Test에 도움이 될 수 있을까 싶어서요.
Object Graph의 하위 특정 영역을 Mock으로 대체하고 테스트하는 것이 목적입니다.

아직 깊이 있게 이해한 건 아니지만 궁금한 것이 있습니다.
IoC Container 가 어떻게 Object Graph를 생성하는지는 대충 이해가 갑니다.

그런데 Mark Seemann의 책에서는 Service Locator 패턴을 안티패턴으로 설명하면서
IoC Container를 애플리케이션 진입점에서 Object Graph를 생성하라고 하던군요.

문제는... 그러면 오브젝트의 "관계"가 애플리케이션 시작시 정적으로 결정되게 되는데...
어떻게 이걸로 전체 프로그램을 디자인 할 수 있는지 의아합니다.

예를 들어, 애플리케이션 진입점 이후 특정 이벤트에 의해 새 오브젝트가 생성되는 경우에는
IoC Container가 관여할 수 없는 것 아닌가 하는 생각입니다.
새 오브젝트를 생성하면서 그 타입을 알아야 하는데..
그 타입까지는 팩토리 클래스를 이용해서 어떻게든 애플리케이션 진입시 주입될 수 있겠지만
그 오브젝트가 하위 Object Graphs를 가지고 있을 때는 그것까지는 어떻게 해결해야 할지 잘 모르겠습니다.

class A: IA
{
     private IB b;
     A(IB bb)
     {
         b=bb;
     }
}

class B1: IB
{
     private IC c;
     A(IC c1)
     {
         c=c1;
     }
}

class B2: IB
{
     private IC c;
     A(IC c1)
     {
         c=c1;
     }
}

즉, 위에서 이벤트에 의해 IA가 생성될 때 IoC Container가 IA의 타입이나, A와 B1, B2의 관계를 지정해 줄 수 있냐 하는 겁니다.

제가 뭘 모르는건지.. 아니면 디자인 문제인지..
혹시 아시는 분 계시면 알려주시면 감사하겠습니다.

익명 사용자의 이미지

그걸 할 수 있다는 걸 스스로 아실겁니다.
다만 비효율적이라고 생각해서 물어보신 것 같습니다.
대답은 스스로 이미 하셨습니다.
안티 패턴은 원래 그래서 안티 패턴입니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.