title: Using Factory with DryIoc and getting object by string
body: <p>I am just testing invertion control using DryIoc library. Please check above to get the picture.</p>
  
  <p>I have that factory class:</p>
  
  <pre><code> 'FactoryConnections using IoC Dry
      Public Class FactoryConnections
  
          Private Shared ReadOnly Container As Container
  
          Shared Sub New()
              Container = New Container()
              With Container
  
                  .Register(Of ISftp, Sftp)
                  .Register(Of ISaop, Soap)
  
                  '.Register(Of IFtp, Ftp)
                  .Register(Of IFtp, Ftp)(serviceKey:= "some string value")
              End With
          End Sub
  
          Public Shared Function ResolveService(Of T As IProtocol)(value As Iprotocol) As T
              Return Container.Resolve(Of T)
          End Function
      End Class
  </code></pre>
  
  <p>Just shortly according to invertion:</p>
  
  <pre><code>A -&gt;  Y  (A uses Y)
  A -&gt; Interface B -&gt; Y (in this case A doesn't know about Y)
  </code></pre>
  
  <p>we can read my solution the same:</p>
  
  <pre><code>A -&gt; IFtp -&gt; Ftp
  </code></pre>
  
  <p>Therefore instead of getting directly object like: Ftp, Sftp or Soap code should ask factory to get one of them based on the interface therefore calling point doesn't know exactly what concrete object is using but it knows who implements that - that's at elast my understanding. Therefore i could ask calling them via interfaces. This is what i am trying to do however from string value (project related requirment). </p>
  
  <pre><code>Dim myProtocol As String = "IFtp"
  </code></pre>
  
  <p>And as mentioned having that i want to get proper object from my factory in this case i should get New instance of Ftp right?</p>
  
  <p><em>Note that parent interface for IFtp, ISoap, ISftp is IProtocol</em> </p>
  
  <p>I was trying like this:</p>
  
  <pre><code>Dim myProtocol As String = "IFtp"
  Dim itemprotocol As type = Type.GetType(myProtocol)
  Dim realprotocolobject = FactoryConnections.ResolveService(TypeOf(itemprotocol)) 
  </code></pre>
  
  <p>and also tried like this:</p>
  
  <pre><code>Dim myProtocol As String = "IFtp"
  Dim realprotocolobject = FactoryConnections.ResolveService(Of IProtocol)(myProtocol)
  </code></pre>
  
  <p>What's wrong, What am i doing wrong?</p>
  
  <p>One more thing: what is the diffrence between those lines?
  (just saw this serviceKey somwhere..)</p>
  
  <pre><code>.Register(Of IFtp, Ftp)
  .Register(Of IFtp, Ftp)(serviceKey:= "some string value") 
  </code></pre>
  
  <p><strong>Further discussionre reference:</strong></p>
  
  <p>Factory class:
  <a href="https://1drv.ms/i/s!AkQvbwpYPYoIh0IqruVthcndFyOM" rel="nofollow noreferrer">https://1drv.ms/i/s!AkQvbwpYPYoIh0IqruVthcndFyOM</a></p>
  
  <p>UnitTestClass:
  <a href="https://1drv.ms/i/s!AkQvbwpYPYoIh0G7iEfy427aJXXw" rel="nofollow noreferrer">https://1drv.ms/i/s!AkQvbwpYPYoIh0G7iEfy427aJXXw</a></p>