0

I have a generic repository, abstract and concrete as below

public interface IGenericRepository<T> where T : class

public class GenericRepository<T> : IGenericRepository<T> where T : class

I then have an repository that inherits from this, again abstract and concrete

public interface ISkyDiveCentreRepository : IGenericRepository<DiveCentre>

public class SkyDiveCentreRepository : GenericRepository<DiveCentre>

In my ninject config I then have

kernel.Bind(typeof(IGenericRepository<>)).To(typeof(GenericRepository<>));
kernel.Bind<ISkyDiveCentreRepository>().To<SkyDiveCentreRepository>();

This is the first time I've tried to do this but am getting the error:

Error   2   The type 'UKSkyDiveCentres.DAL.imp.SkyDiveCentreRepository' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax<T1>.To<TImplementation>()'. There is no implicit reference conversion from 'SkyDiveCentres.DAL.imp.SkyDiveCentreRepository' to 'SkyDiveCentres.DAL.ISkyDiveCentreRepository'. C:SOMEPATH\UKSkyDiveCentres\App_Start\NinjectWebCommon.cs   56  13  SkyDiveCentres
Paulo Morgado
  • 14,111
  • 3
  • 31
  • 59
Simon
  • 1,966
  • 5
  • 21
  • 35

1 Answers1

1

Your SkyDiveCentreRepository inherits from GenericRepository<DiveCentre> and doesn't implement the ISkyDiveCentreRepository interface.

Simply explicitly implement it:

public class SkyDiveCentreRepository : 
    GenericRepository<DiveCentre>, ISkyDiveCentreRepository
                               //  ^^^^^^^^^^^^^^^^^^^^^^^^ this

Without it.. you can't do simple things like this:

ISkyDiveCentreRepository repo = new SkyDiveCentreRepository();

If you can't do it.. Ninject can't either.

Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
  • Argghh!! Excellent that's done the trick, always good to get some fresh eyes on things!! – Simon Feb 22 '14 at 11:03