![](/img/trans.png)
[英]Castle Windsor: how to register multiple types as implementing a specific interface?
[英]Castle Windsor register multiple types of a base Interface?
我知道如何使用Autofac做到這一點,但不了解Castle。
public interface IAmBaseInterface {}
public interface IAmInterface : IAmBaseInterface {...}
public class AmClass : IAmInterface {...}
我想使用IAmBaseInterface注冊實現AmClass(和任何其他實現)。 這可能嗎? 我嘗試了以下操作,但未注冊類型。
container.Register(Classes.FromThisAssembly().BasedOn<IAmBaseInterface>()
.WithServiceAllInterfaces();
也嘗試過此方法,類似於AutoFac,但沒有成功。
container.Register(Classes.FromThisAssembly()
.Where(t => typeof(IAmBaseInterface).IsAssignableFrom(t)).WithService.AllInterfaces();
我意識到我在代碼中使用了Classes.From(Type [] ...),而不是示例中的Classes.FromThisAssembly。 顯然,它不會掃描多個程序集以基於實現來查找。 我還發現它不會掃描多個程序集來查找內部實現,但這是一個附帶說明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.