Castle Windsor 在不创建实例的情况下解析服务实现类型
Posted
技术标签:
【中文标题】Castle Windsor 在不创建实例的情况下解析服务实现类型【英文标题】:Castle Windsor resolve types of service implementations without creating instances 【发布时间】:2013-07-03 04:28:24 【问题描述】:在 Castle Windsor IoC 中,如果您想查找注册服务的类型,可以通过以下方式进行:
List<Type> typeList = new List<Type>();
foreach (var item in moduleContainer.ResolveAll<IMyService>())
var theType = typeof(item);
Console.WriteLine("Found implementation: " + item.Name);
typeList.insert(theType);
然而,这个方法实际上创建了一个实例。
如何在不创建实例的情况下解决服务接口的实现Type
(s)?
【问题讨论】:
我想您可以在将其添加到列表后立即moduleContainer.Release(item)
。有没有更好的办法?
【参考方案1】:
var handlers = container.Kernel.GetHandlers(typeof(IMyService));
【讨论】:
很抱歉再次访问此内容,但它不会返回Type
对象,而这正是我在这里所需要的。有没有办法从 IHandler 获取Type
?
handler.ComponentModel.Implementation
以上是关于Castle Windsor 在不创建实例的情况下解析服务实现类型的主要内容,如果未能解决你的问题,请参考以下文章
使用 SignalR Hub 内的 Windsor Castle 工作单元
使用 Castle Windsor 解析 HttpControllerContext
Castle Windsor 3 + Fluent NHibernate + Castle.NHibernate.Integration
Castle.Windsor依赖注入的高级应用_Castle.Windsor.3.1.0