I hawe all day strugle my head and i canot find any solution to my case so i nead help. Hear is my problem: I hawe two classes that implement one interface
public interface ICacheObject
{
string Get();
}
public class WebCacheObject : ICacheObject
{
public string Get()
{
return "Web";
}
}
public class SysteCacheObject : ICacheObject
{
public string Get()
{
return "System";
}
}
So in some other clase For Example in Class Test I nead to inject the WebCacheObject and in Test2 clase i nead to inject SystemCacheObject. I did this in Initialize:
ObjectFactory.Initialize(c =>{ c.For<IMessage>().Use<Message>();
c.For<ICacheObject>().ConditionallyUse(t =>{t.If(g => g.RequestedName == "HTTP")
.ThenIt.Is.ConstructedBy(
() =>
new WebCacheObject());
t.If(g =>g.RequestedName =="OtherCache")
.ThenIt.Is.ConstructedBy(
() =>
new SysteCacheObject
());
});
But I dont know how to Call Test-s clase-s so if I call so the condition is true (or how to change condition so this will work)
ObjectFactory.GetInstance<'ITest>()
the Test Clase will hawe WebCache in other case SystemCache???
Sorry for my bad English.