如何将 Ninject xml 配置与 TEntity 一起使用?

How to use the Ninject xml config with TEntity?

这应该有效:-

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

其中:-

IRepository<> 是以下形式的接口:-

public interface IRepository<T> where T :class 
{

     //...

}

Repository<> 是一个 class 的形式:-

public class Repository<T>:IRepository<T> where T :class
{

    //...

}

但是如何使用 Ninject.Extensions.Xml 在 XML 配置中做到这一点?

没用。

您可以通过typeof(IRepository<>).FullName找出类型的名称,然后按如下方式配置XML:

<module name="myXmlConfigurationModule">
    <bind service="MyNamespace.IRepository`1, MyAssembly"
          to="MyNamespace.Repository`1, MyAssembly" />
</module>

我之前没有使用 Ninject 的 XML 扩展,但是 应该 工作