title: Injecting F-bound polymorphic types by interface
body: <p>I am attempting to develop a small component for a Play-based service and am struggling with how to go about the design. I need a service that provides access to "file storage" in various environments. My initial idea is simply to create a trait that represents the two primary operations (write/read) and then autowire the implementation based on configuration at runtime. The interface looks something like the following:</p>
  
  <pre><code>trait StorageService {
    def saveFile(name: String): Sink[ByteString, Future[Try[FileHandle]]]
    def readFile(handle: FileHandle): Source[ByteString]
  }
  </code></pre>
  
  <p>The service allows a user to save a file to disk and returns a <code>FileHandle</code> object that contains all of the information the service needs to identify the specific file. The issue I'm having is that the <code>FileHandle</code> needs different information for each concrete implementation. Now, I can use F-bound polymorphism on the trait to solve this like so:</p>
  
  <pre><code>trait StorageService[A &lt;: FileHandle] {
    def saveFile(name: String): Sink[ByteString, Future[Try[A]]]
    def readFile(handle: A): Source[ByteString]
  }
  </code></pre>
  
  <p>However, the issue here becomes autowiring as I cannot wire the concrete implementations as <code>StorageService</code> providers without specifying the type parameter. Does anyone have a suggestion on how to accomplish this autowiring or perhaps a better design? </p>