StructureMap singleton behavior not working
Posted
by user137348
on Stack Overflow
See other posts from Stack Overflow
or by user137348
Published on 2009-12-18T12:09:55Z
Indexed on
2010/05/18
5:30 UTC
Read the original article
Hit count: 184
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.
© Stack Overflow or respective owner