gpt4 book ai didi

c# - 城堡温莎 : Register generics with more than one items

转载 作者:行者123 更新时间:2023-11-30 22:14:55 24 4
gpt4 key购买 nike

我有一个这样定义的通用接口(interface) -

public interface IGenericRepository<TEntity, TDbContextType>
where TEntity : class
where TDbContextType : IDbContextType

这个接口(interface)是由这样一个类实现的——

 public class GenericRepository<TEntity,TDbContextType> 
: IGenericRepository<TEntity, TDbContextType>
where TEntity : class
where TDbContextType: IDbContextType

我尝试了以下方法来使用 caSTLe 注册这个接口(interface)和实现 -

   _container.Register(Component.For(typeof (IGenericRepository<>))
.ImplementedBy(typeof (GenericRepository<>))
.LifestylePerWcfOperation());

但它在编译时失败,说“参数数量不正确”。

最佳答案

它无法编译,因为您使用一个参数指定了泛型类型,但您定义了具有两个参数的类型。

所以你应该使用IGenericRepository<,>GenericRepository<,>而不是 IGenericRepository<>GenericRepository<> .

关于c# - 城堡温莎 : Register generics with more than one items,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18252204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com