繁体   English   中英

温莎城堡:注册具有多个项目的仿制药

[英]Castle windsor: Register generics with more than one items

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

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

我尝试了以下方法来向Castle注册此接口和实现-

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

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

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

因此,您应该使用IGenericRepository<,>GenericRepository<,>而不是IGenericRepository<>GenericRepository<>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM