How to use the Ninject xml config with TEntity?

90 views Asked by At

This should work:-

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

where:-

IRepository<> is an interface of the form:-

public interface IRepository<T> where T :class 
{

     //...

}

Repository<> is a class of the form:-

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

    //...

}

But how to do it in XML configuration using Ninject.Extensions.Xml?

It does not work.

1

There are 1 answers

0
Trevor Pilley On BEST ANSWER

You can find out what the name of the type is by doing typeof(IRepository<>).FullName and then configure the XML as follows:

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

I haven't used the XML extensions for Ninject before, but that should work