views:

216

answers:

1

I have setup unity in my project and it is working for objects that don't have constructor injection implemented on them. The issue is now I do have an object which requires a custom object as a constructor argument. I have set up the config below, and this errors telling me that "TypeConverter cannot convert from System.String"

<unity>    
  <typeAliases>    
    <typeAlias alias="TransactionRepositoryInterface" type="Ib.TransactionViewer.DataAccess.ITransactionRepository, Ib.TransactionViewer.DataAccess" />    
    <typeAlias alias="TransactionRepositoryToUse" type="Ib.TransactionViewer.DataAccess.TransactionRepository, Ib.TransactionViewer.DataAccess" />    
  </typeAliases>
  <containers>    
    <container>    
      <types>    
        <type type="TransactionRepositoryInterface" mapTo="TransactionRepositoryToUse">    
          <lifetime type="singleton" />    
          <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">    
            <constructor>    
              <param name="TransactionProcessor" parameterType="Ib.TransactionViewer.DataAccess.TransactionProcessor, Ib.TransactionViewer.DataAccess">    
                <value value="Ib.TransactionViewer.DataAccess.TransactionProcessor" type="Ib.TransactionViewer.DataAccess.TransactionProcessor, Ib.TransactionViewer.DataAccess" />    
              </param>
            </constructor>     
          </typeConfig>    
        </type>    
      </types>
    </container>    
  </containers>    
</unity>
+1  A: 

I am not sure but it's looks to me that unity is trying to use value

Ib.TransactionViewer.DataAccess.TransactionProcessor

as a String.

Maybe you should write something like:

    <unity>    
  <typeAliases>    
    <typeAlias alias="TransactionRepositoryInterface" type="Ib.TransactionViewer.DataAccess.ITransactionRepository, Ib.TransactionViewer.DataAccess" />    
    <typeAlias alias="TransactionRepositoryToUse" type="Ib.TransactionViewer.DataAccess.TransactionRepository, Ib.TransactionViewer.DataAccess" />    
  </typeAliases>
  <containers>    
    <container>    
      <types>    
        <type type="TransactionRepositoryInterface" mapTo="TransactionRepositoryToUse">    
          <lifetime type="singleton" />    
          <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">    
            <constructor>    
              <param name="TransactionProcessor" parameterType="Ib.TransactionViewer.DataAccess.TransactionProcessor, Ib.TransactionViewer.DataAccess">    
                <dependency />    
              </param>
            </constructor>     
          </typeConfig>    
        </type>    
      </types>
    </container>    
  </containers>    
</unity>
Mijalko