2

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
  • 1
    Is using the XML configuration a requirement? I much prefer the Fluent in-code configuration; I suspect you'd find it easier to read and debug. Commented Nov 15, 2009 at 17:27

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.