Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net Castle Windsor:使用非泛型接口注册泛型类_.net_Castle Windsor - Fatal编程技术网

.net Castle Windsor:使用非泛型接口注册泛型类

.net Castle Windsor:使用非泛型接口注册泛型类,.net,castle-windsor,.net,Castle Windsor,我有一个类,它有几个依赖项: public class ThirdPartyDataSearchCoordinator<TItem, TSearchCriteria, TResult> : IThirdPartyDataSearchCoordinator where TItem : class, IThirdPartyItem { public ThirdPartyDataSearchCoordinator(IDataMiner<TSearchCrite

我有一个类,它有几个依赖项:

public class ThirdPartyDataSearchCoordinator<TItem, TSearchCriteria, TResult> : IThirdPartyDataSearchCoordinator where TItem : class, IThirdPartyItem
    {
        public ThirdPartyDataSearchCoordinator(IDataMiner<TSearchCriteria, TResult>[] miners, IThirdPartyItemRepository<TItem> repository, IMappingEngine mapper, IUpdater<TItem, TResult> updater)
        {
            this.miners = miners;
            this.repository = repository;
            this.mapper = mapper;
            this.updater = updater;
        }
}
然而,当我尝试:

ServiceLocator.Current.GetInstance<IThirdPartyDataSearchCoordinator>()
ServiceLocator.Current.GetInstance()
卡斯尔抱怨说:

Castle.MicroKernel.Handlers.HandlerException: 无法创建组件 '应用程序服务.ThirdPartyData.ThirdPartyDataSearchCoordinator
3'
因为它有依赖关系
满意的。
应用程序服务.第三方数据.第三方数据搜索协调器
3 正在等待以下消息 依赖项:

服务: -未注册的i irdPartyItemRepository
1。
-IUpdater
2未注册

键(具有特定键的组件) -未登记的矿工

我是否遗漏了一些东西——或者我对Castle的期望过高,以至于无法以这种方式解决泛型依赖关系

编辑 我想做的是显式注册我打算针对应用程序中的
I irdPartyDataSearchCoordinator
接口使用的每个具体
ThirdPartyDataSearchCoordinator

我不想让界面变得通用,因为那样我就无法保存不同的
I irdpartyDataSearchCoordinator
集合


我如何告诉castle显式初始化,例如,一个
ThirdPartyDataSearchCoordinator
,而不必手动将所有依赖项输入构造函数?

不是100%确定,但我认为您需要先注册开放的通用接口然后您可以覆盖特定的实现


请看

好的,我花了不少时间研究了一个解决方案。我将“AllTypes”注册更改为仅注册非泛型类型

container.Register(AllTypes.Pick()
.FromAssemblyNamed(Assembly.GetAssembly(typeof(IUpdater<,>)).GetName().Name)
.If(p => !p.ContainsGenericParameters)
.WithService.FirstInterface());
container.Register(AllTypes.Pick())
.FromAssemblyName(Assembly.GetAssembly(typeof(IUpdater)).GetName().Name)
.If(p=>!p.ContainsGenericParameters)
.WithService.FirstInterface());
现在一切都很好。我认为所有类型和泛型类注册都存在一些问题

更新
简单地将我的泛型类注册放在AllTypes之前也可以做到这一点。

Hi mausch。我就知道你会来回答这个问题!我不想使接口通用,因为那样我就无法保存不同的ITIRDPartyDataSearchCoordinator集合。我已经编辑了这个问题。。。还有什么想法吗?这里的类和接口太多了。。。给我一个复制这个的精简解决方案,我会检查一下。好的,我不太确定如何与你联系。只需将每个类和接口放在一个文件中,并将其放入或发送给我URL。好的,我想我已经将问题缩小到一个非常简单的问题。我希望能够针对非泛型接口注册泛型类,请参阅
ServiceLocator.Current.GetInstance<IThirdPartyDataSearchCoordinator>()
container.Register(AllTypes.Pick()
.FromAssemblyNamed(Assembly.GetAssembly(typeof(IUpdater<,>)).GetName().Name)
.If(p => !p.ContainsGenericParameters)
.WithService.FirstInterface());