I am registering a class with StructureMap, which includes TimeSpan in the constructor parameters, and another TimeSpan as a class property. When I use the named constructor argument in StructureMap, the value for the constructor argument is applied to my constructor parameter and any public class properties that are TimeSpans. I also tried switching the class to DateTimes instead of TimeSpans and got the same result. So my question is: am I using StructureMap correctly or should I register this class in another way? Thanks!
The following is a simple interface and class to demonstrate the problem:
public interface ITimeSpanTest
{
TimeSpan Timeout { get; set; }
TimeSpan LogTimeout { get; set; }
}
public class TimeSpanTest : ITimeSpanTest
{
public TimeSpan LogTimeout { get; set; }
public TimeSpan Timeout { get; set; }
public string Process { get; set; }
public TimeSpanTest(TimeSpan logTimeout, string process)
{
this.Timeout = TimeSpan.FromSeconds(1);
this.LogTimeout = logTimeout;
this.Process = process;
}
}
and this is the registration code of StructureMap
Container container = new Container();
container.Configure(c =>
{
c.Scan(x =>
{
x.TheCallingAssembly();
});
c.For<ITimeSpanTest>().Use<TimeSpanTest>()
.Ctor<TimeSpan>("logTimeout").Is(TimeSpan.FromMinutes(5))
.Ctor<string>("process").Is("Process")
.Singleton();
});
This is the output of the StructureMap.Model.For () container. Function Default.DescribeBuildPlan ()
PluginType: SMTest.ITimeSpanTest
Lifecycle: Singleton
new TimeSpanTest(TimeSpan, String process)
? TimeSpan = Value: 00:05:00
? String process = Value: Process
Set TimeSpan LogTimeout = Value: 00:05:00
Set TimeSpan Timeout = Value: 00:05:00
, "logTimeout" TimeSpan . Timeout 00:05:00, 00:00:01. StructureMap 3.1.6.186.