我不明白,在IOC的所有例子中,我可以发现,一个接口只能在类映射的字典中实现一个类。无论DI还是服务定位器为什么IOC的例子只有OneInterface:OneClass比例?
这在我看来有点愚蠢,不是吗?
我不明白,在IOC的所有例子中,我可以发现,一个接口只能在类映射的字典中实现一个类。无论DI还是服务定位器为什么IOC的例子只有OneInterface:OneClass比例?
这在我看来有点愚蠢,不是吗?
所有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");
有更多的容器支持这个;这些只是例子。我的书包含更多详细的例子。
非常感谢:) –
请不要使用您的书的联盟链接 - http://meta.stackexchange.com/questions/2716/affiliate-links-amazon-and-others – ChrisF
请使用一个不太冒犯的例子 – ChrisF