Castle Windsor using wrong component to satisfy a dependency
Posted
by Neil Barnwell
on Stack Overflow
See other posts from Stack Overflow
or by Neil Barnwell
Published on 2010-06-09T15:41:28Z
Indexed on
2010/06/09
16:12 UTC
Read the original article
Hit count: 639
I have the following component mapping in Windsor xml:
<component
id="dataSession.DbConnection"
service="System.Data.IDbConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
type="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
lifestyle="custom"
customLifestyleType="MyCompany.Castle.PerOperationLifestyle.PerOperationLifestyleManager, MyCompany.Castle">
<parameters>
<connectionString>server=(local);database=MyCompany;trusted_connection=true;application name=OperationScopeTest;</connectionString>
</parameters>
</component>
<component
id="dataSession.DataContext"
service="System.Data.Linq.DataContext, System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"
type="MyCompany.BusinessLogic.MyCompanyDataContext, MyCompany.BusinessLogic"
lifestyle="custom"
customLifestyleType="MyCompany.Castle.PerOperationLifestyle.PerOperationLifestyleManager, MyCompany.Castle">
<parameters>
<connection>${dataSession.DbConnection}</connection>
</parameters>
</component>
However, when I ask the container for a DataContext
, it actually uses the constructor requiring a connection string, despite the ${dataSession.DbConnection}
being an IDbConnection
.
Why is this, and how to I make Windsor use the correct constructor?
© Stack Overflow or respective owner