My code is
public static class ContainerBootstrapper
{
public static void BootstrapStructureMap()
{
ObjectFactory.Initialize(x => x
.ForRequestedType<ValueHolder>()
.CacheBy(InstanceScope.Singleton)
.TheDefaultIsConcreteType<ValueHolder>());
}
}
Initialization code (its a windows service)
static class Program
{
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{ new AppServer() }; ServiceBase.Run(ServicesToRun);
ContainerBootstrapper.BootstrapStructureMap();
}
}
And then I call an instance like this:
var valueHolder = ObjectFactory.GetInstance<ValueHolder>();
But I get everytime an new instance not the one used before.