title: Dependency injection with interface in go
body: <p>I have a struct <code>StructDependingOnInterface</code> which depends on <code>MyInterface</code> interface. I'd like the struct <code>Implementation</code> to be injected into <code>bar</code> when <code>StructDependingOnInterface</code> is instantiated.</p>
  
  <p>I have tried doing this with facebookgo/inject library, but it seems like it doesn't work with interfaces. <code>s.bar</code> is always nil.</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "log"
  
      "github.com/facebookgo/inject"
  )
  
  type MyInterface interface {
      Foo()
  }
  
  type Implementation struct{}
  
  func (imp *Implementation) Foo() {
      fmt.Println("Hello")
  }
  
  type StructDependingOnInterface struct {
      bar MyInterface `inject:""`
  }
  
  func main() {
      var g inject.Graph
  
      err := g.Provide(
          &amp;inject.Object{Value: &amp;Implementation{}},
      )
      if err != nil {
          log.Fatal(err)
      }
  
      g.Populate()
  
      s := &amp;StructDependingOnInterface{}
      s.bar.Foo()
  }
  </code></pre>
  
  <p>Does the language go allows what I'm trying to do ?</p>
  
  <p>Is there an alternative of facebookgo/inject that would fits my need ?</p>