温莎城堡: - 通过配置接口注入词典 [英] Windsor Castle :- Inject Dictionary of Interfaces via configuration

查看:261
本文介绍了温莎城堡: - 通过配置接口注入词典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我试图注入接口词典,但我得到一个错误,从城堡是这样的: -



Castle.MicroKernel.SubSystems.Conversion.ConverterException:否转换器注册后处理类型的IFoo



为了去例外的时候,我不得不创建一个包含的IFoo接口的列表,并使用属性返回它的包装。然后包装在配置中使用==>字典而不是字典



有没有城堡的方式只是我能接口的字典而不是做这个的解决方法?

 公共接口的IFoo {} 
公共类Foo {}
公共类IfooWrapper {
的IList<的IFoo>容器{获取;集;}
}


解决方案

我已经做的非常类似的事情。不过,我认为这暴露设计缺陷比什么都重要。我重构我的应用程序,以便它没有你的包装类做什么工作作为它的标准方式。它大大简化了应用程序也是如此。



这真的只是在做的事情了温莎城堡的方式,而不是试图为我的路适应城堡的事温莎模式。这是非常震撼人心看到更容易,更好的温莎城堡的方式怎么样?



从技术上讲不是你提出但希望它可以帮助你解决问题的办法。


Hi i am trying to inject a dictionary of interfaces but am getting an error from castle like this :-

Castle.MicroKernel.SubSystems.Conversion.ConverterException: No converter registered to handle the type IFoo

In order to go around the exception, I had to create a wrapper that contained a list of the Ifoo interface and returns it using a property. The wrapper was then used in the configuration ==> dictionary instead of dictionary

Is there a way in castle that I can just have a dictionary of Interface instead of doing this workaround ?

public interface IFoo {}
public class Foo {}
public class IfooWrapper {
    IList<IFoo> container{get;set;}
}

解决方案

I've had to do something very similar. However I think it exposed a design flaw more than anything else. I refactored my app so that it did what your wrapper class does as its standard way of working. It drastically simplified the app as well.

It was really just a matter of doing things the "Castle Windsor way" instead of trying to adapt "my way" to the Castle Windsor model. It was pretty humbling to see how much easier and better the Castle Windsor way was...

Technically not a solution to the problem you posed but hopefully it helps you out.

这篇关于温莎城堡: - 通过配置接口注入词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆