I have registered 5 derived classes for the same interface using named instances. All these classes are registered as Singleton
For<IBaseInterface>().Singleton().Use<DerivedClass1>().Named("Derived1");
For<IBaseInterface>().Singleton().Use<DerivedClass2>().Named("Derived2");
For<IBaseInterface>().Singleton().Use<DerivedClass3>().Named("Derived3");
There is a static class which resolves the instance based on input. However I observed that every call to ObjectFactory.GetInstance returns new instances on every request instead of a Singleton. There are no threads in the application as well.
Any idea on why this is happening?
Edit:
Does a static resolution helper cause any issues? This is the way I am resolving the instance. Singleton works properly in a sample application but it doesnt work on my machine.
To add some more details - the project is MVC Web API and I am testing on local IIS. I am positive there are no user created threads in the application.
public static class Resolver
{
public static IBaseInterface GetHelper(string inputParam)
{
if inputParam is "Case1"
return ObjectFactory.GetInstance<IBaseInterface>("Derived1")
//Similarly for other instances
}
}
GetInstance
andGetNamedInstance
.GetInstance
returns the last registered instance every time.GetNamedInstance("Derived1")
returns the same instance ofDerivedClass1
every time. – Grantor