简体   繁体   English

在类型中使用两个泛型参数进行 Ninject 绑定

[英]Ninject binding with two generic parameters in types

I have this interface:我有这个界面:

public interface IRepository<TDomain, TBusiness>
    where TDomain : class
    where TBusiness : class
    {...}

And this class:而这个类:

public class Repository<TDomain, TBusiness> : IRepository<TDomain,    TBusiness>
    where TDomain : class
    where TBusiness : class
    {...}

And when i bind in with ninject, something like:当我用 ninject 绑定时,类似于:

Kernel.Bind(typeof(IRepository<>))
      .To(typeof(Repository<>))
      .InRequestScope();

And have an error "Incorrect number of type parameters in ...".并出现错误“...中的类型参数数量不正确”。 When I have only one generic in type everything works fine.当我只有一个泛型类型时,一切正常。 Have anyone solution to fix this problem?有没有人解决这个问题的解决方案?

This has nothing to do with Ninject, the error you are getting is a C# compiler error.这与 Ninject 无关,您得到的错误是 C# 编译器错误。 That's because the correct way to specify a type with two generic arguments is the following:这是因为使用两个泛型参数指定类型的正确方法如下:

typeof(IRepository<,>)

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

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