Castle windsor:使用多个项目注册泛型

时间:2013-08-15 11:59:57

标签: c# c#-4.0 dependency-injection castle-windsor castle

我有一个像这样定义的通用接口 -

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

此接口由类似这样的类实现 -

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

我尝试了以下注册这个接口和实现与城堡 -

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

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

1 个答案:

答案 0 :(得分:3)

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

因此,您应该使用IGenericRepository<,>GenericRepository<,>代替IGenericRepository<>GenericRepository<>

相关问题