title: Dependency injection with associated types causing arguments without type names (undescores) in Swift
body: <p>The situation is following: I'm using a protocol to inject dependencies and the best way I found to implement this in Swift is to use the <code>associatedtype</code> keyword. I am also using protocol composition since some implementations of <code>TestProtocol</code> need more than one dependency.</p>
  
  <pre class="lang-swift prettyprint-override"><code>protocol TestProtocol: class {
      associatedtype Dependencies
      func inject(_ dependency: Dependencies)
  }
  
  protocol HasSomething {
      var something: Something { get set }
  }
  
  protocol HasSomethingElse {
      var somethingElse: SomethingElse { get set }
  }
  </code></pre>
  
  <p>To use this I found that I'll need to use generics like this:</p>
  
  <pre class="lang-swift prettyprint-override"><code>class TestService&lt;T&gt; where T: TestProtocol, T.Dependencies == TestService {
  
      weak var testProtocol: T?
  
      init(with testProtocol: T) {
          self.testProtocol = testProtocol        
          self.testProtocol?.inject(self)
      }
  }
  </code></pre>
  
  <p>Now when I want to use this service somewhere else and I'm trying to initiate it I get following problem:</p>
  
  <p><a href="https://i.stack.imgur.com/n0fVX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n0fVX.png" alt="problem with generics"></a></p>
  
  <p>The parameter is displayed as <code>_</code> and not as the protocol name <code>TestProtocol</code>. </p>
  
  <p>Let's say I would use this code in a library. How would a user know (without reading the documentation of course) what type could be used in this context when he is not even knowing what protocol he has to implement?</p>
  
  <p>Is there a better way on how to use dependency injection with the type actually being displayed to the user, or am I doing something wrong in the <code>where</code> clause of the <code>TestService</code> class, or is this simply not possible in the current versions of Swift?</p>