Does Windsor lock permit value type resolution?

I am trying to pass a parameter to a component that requires System.TimeSpan. I can only get the permission of the "long ticks".

Here is a snippet of the configuration file:

<component id="timeInForce" type="System.TimeSpan, mscorlib">
  <parameters>
    <hours>0</hours>
    <minutes>15</minutes>
    <seconds>0</seconds>
  </parameters>
</component>

<component id="FooSettings" type="Foo.FooSettings, Foo">
    <parameters>
        <tif>${timeInForce}</tif>
    </parameters>
</component>

This is an exception:

Castle.MicroKernel.Handlers.HandlerException : Cant create component 'timeInForce'
as it has dependencies to be satisfied. 
timeInForce is waiting for the following dependencies: 

Keys (components with specific keys)
    - ticks which was not registered.

Passing a tick value for a component parameter works as in:

<parameters><tif>0</tif></parameters>

but it defeats the goal.

+3
source share
1 answer

What happens (from what I see) is that the ticks property is incorrectly identified as a forced parameter (because it belongs to the constructor with the least number of arguments), although all value types have a default parameter without constructor parameters.

-, , , (.. ), , :

<component id="timeInForce"" type="System.TimeSpan, mscorlib">
<parameters>
  <ticks>0</ticks>
  <hours>0</hours>
  <minutes>15</minutes>
  <seconds>0</seconds>
</parameters>
</component>

, , ( ):

string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?> 
<castle>
<components>
<component id=""timeInForce"" type=""System.TimeSpan, mscorlib"">
<parameters>
  <ticks>0</ticks>
  <hours>0</hours>
  <minutes>15</minutes>
  <seconds>0</seconds>
</parameters>
</component>
</components>
</castle>";

WindsorContainer container = new WindsorContainer(
  new XmlInterpreter(new StaticContentResource(xml)));

TimeSpan span = container.Resolve<TimeSpan>("timeInForce");

Assert.AreEqual(new TimeSpan(0, 15, 0), span);

, , , , - , .

, , "15 " "215 ", -, - , .

+4
source

Source: https://habr.com/ru/post/1699194/


All Articles