Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3402660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:09:55+00:00 2026-05-18T05:09:55+00:00

I have the following three components defined in the Caste-Windsor XML configuration for my

  • 0

I have the following three components defined in the Caste-Windsor XML configuration for my application:

<component id="StringFactory"
           service="IStringFactory, MyApp"
           type="DefaultStringFactory, MyApp"
           lifestyle="singleton"
           />

<component id="TheString"
           type="System.String"
           factoryId="StringFactory"
           factoryCreate="CreateString"
           >
  <parameters>
    <name>SomeString</name>
  </parameters>
</component>

<component id="TheTarget"
           service="ITarget, MyApp"
           type="TheTarget, MyApp"
           lifestyle="transient"
           >
  <parameters>
    <aString>${TheString}</aString>
  </parameters>
</component>

And the following facility defined:

<facility id="factory.support"
          type="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel"
          />

When I run the application and set a breakpoint in the constructor of the TheObject class, the value passed in as the aString parameter is “${TheString}” when I expect it to resolve to the value of the component with that name.

Also, I have a breakpoint in the StringFactory constructor and CreateString method, neither of which are hit. I know the configuration is being used as other components are resolving correctly.

What am I missing or doing wrong here?

UPDATE

In light of the huge tangient this topic has taken, I’ve refactored the code above to remove anything to do with connection strings. The original intent of this post was about injecting a property with the value returned from a method on another object. Somehow that point was lost in a discussion about why I’m using XML versus code-based configuration and if this is a good way to inject a connection string.

The above approach is far from an original idea and it was pulled from several other discussions on this topic and our requirements are what they are. I’d like help understanding why the configuration as it is in place (whether the right approach or not) isn’t working as expected.

I did verify that the first two components are being instantiated correctly. When I call Container.Resolve(“TheString”), I get the correct value back. For whatever reason, The parameter syntax is not working correctly.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:09:56+00:00Added an answer on May 18, 2026 at 5:09 am

    While not a definitive solution to what I need to do in my application, I believe I’ve figured out what is wrong with the code. Or at least I’ve found a way to make it work which hints at the original problem.

    I replaced the String type for TheString with a custom class. That’s it. Once I did that, everything worked fine.

    My guess is that it has something to do with the fact that I was trying to use a ValueType (primitive) as a component. I guess Castle doesn’t support it.

    So, knowing that’s the case, I can now move on to figuring out if this approach is really going to work or if we need to change direction.

    UPDATE

    For the sake of completeness, I thought I’d go ahead and explain what I did to solve my problem AND satisfy my requirements.

    As before, I have access to my configuration settings through an IConfigurationService defined as:

    <component id="ConfigurationService"
               service="MyApp.IConfigurationService, MyApp"
               type="MyApp.RuntimeConfigurationService, MyApp"
               lifestyle="singleton"
               />
    

    This is automatically injected into my (new) IConnectionFactory which is responsible for generating IDbConnection objects based on the connection strings defined in the application’s configuration file. The factory is declared as:

    <component id="ConnectionFactory"
               service="MyApp.Factories.IConnectionFactory, MyApp"
               type="MyApp.Factories.DefaultConnectionFactory, MyApp"
               lifestyle="singleton"
               />
    

    In order to resolve what connection is used by my repository, I declare each connection as a component using the ConnectionFactory to create each instance:

    <component id="MyDbConnection"
               type="System.Data.IDbConnection,
                     System.Data, Version=2.0.0.0, Culture=neutral,
                     PublicKeyToken=b77a5c561934e089"
               factoryId="ConnectionFactory"
               factoryCreate="CreateConnection"
               lifestyle="transient"
               >
      <parameters>
        <connectionStringName>MyDB</connectionStringName>
      </parameters>
    </component>
    

    Notice the fully described reference to System.Data. I found this is necessary whenever referencing assemblies in the GAC.

    Finally, my repository is defined as:

    <component id="MyRepository"
               service="MyApp.Repositories.IMyRepository, MyApp"
               type="MyApp.Sql.SqlMyRepository, MyApp.Sql"
               lifestyle="transient"
               >
      <parameters>
        <connection>${MyDbConnection}</connection>
      </parameters>
    </component>
    

    Now everything resolves correctly and I don’t have ANY hard-coded strings compiled into my code. No connection string names, app setting keys or whatever. The app is completely reconfigurable from the XML files which is a requirement I must satisfy. Plus, other devs that will be working with the solution can manage the actual connection strings in the way they are used to. Win-win.

    Hope this helps anyone else that runs into a similar scenario.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the three following lists A1 A2 A3 B1 B2 C1
I have the following template <h2>one</h2> <xsl:apply-templates select=one/> <h2>two</h2> <xsl:apply-templates select=two/> <h2>three</h2> <xsl:apply-templates select=three/>
I have three images and using the following code I have then fade in
I have a calc function in java script that takes three integer parameters, following
If I have a comma separated file like the following: foo,bar,n ,a,bc,d one,two,three ,a,bc,d
I am using a Tab Navigator component in which there are three canvas components.
I have the following situation: There is a tool that gets an XSLT from
I have the following 3 classes Book Product SpecialOptions There are many Books, and
I have the following code that won't compile and although there is a way
Avast there fellow programmers! I have the following problem: I have two rectangles overlapping

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.