public static void Main()
var incorrectContainer = new Container(_ => {
_.For<LocalizationContext>().Use<LocalizationContext>();
_.For<ISomeDependency>().Use<SomeDependency>();
_.For<FancyLocalizationContext>().Use<FancyLocalizationContext>();
_.For<ISomeDependency>().Use<FancyDependency>();
var localizationContext = incorrectContainer.GetInstance<LocalizationContext>();
var fancyLocalizationContext = incorrectContainer.GetInstance<FancyLocalizationContext>();
Console.WriteLine(localizationContext.Foo());
Console.WriteLine(fancyLocalizationContext.Foo());
var correctContainer = new Container(_ => {
_.For<LocalizationContext>().Use<LocalizationContext>();
_.For<ISomeDependency>().Use<SomeDependency>();
_.For<FancyLocalizationContext>().Use<FancyLocalizationContext>()
.Ctor<ISomeDependency>().Is<FancyDependency>();
var localizationContext1 = correctContainer.GetInstance<LocalizationContext>();
var fancyLocalizationContext1 = correctContainer.GetInstance<FancyLocalizationContext>();
Console.WriteLine(localizationContext1.Foo());
Console.WriteLine(fancyLocalizationContext1.Foo());
public class LocalizationContext
private readonly ISomeDependency _someDependency;
public LocalizationContext(ISomeDependency someDependency)
_someDependency = someDependency;
public string Foo(){ return "::[LocalizationContext:] I have a:\r\n\t" + _someDependency.Bar(); }
public class FancyLocalizationContext
private readonly ISomeDependency _someDependency;
public FancyLocalizationContext(ISomeDependency someDependency)
_someDependency = someDependency;
public string Foo(){ return "::[LocalizationContext:] I have a:\r\n\t" + _someDependency.Bar();; }
public interface ISomeDependency
public class SomeDependency : ISomeDependency
public string Bar() { return "A Dependency"; }
public class FancyDependency : ISomeDependency
public string Bar() { return "A Struct"; }