回答

2

所有DI容器我在同一个界面my book支持多个注册穿行:

温莎城堡

container.Register(Component 
    .For<IIngredient>() 
    .ImplementedBy<Steak>()); 
container.Register(Component 
    .For<IIngredient>() 
    .ImplementedBy<SauceBéarnaise>()); 

Autofac

builder.RegisterType<SauceBéarnaise>().As<IIngredient>(); 
builder.RegisterType<Steak>().As<IIngredient>(); 

统一

container.RegisterType<IIngredient, Steak>(); 
container.RegisterType<IIngredient, SauceBéarnaise>("sauce"); 

有更多的容器支持这个;这些只是例子。我的书包含更多详细的例子。

+0

非常感谢:) –

+1

请不要使用您的书的联盟链接 - http://meta.stackexchange.com/questions/2716/affiliate-links-amazon-and-others – ChrisF