You have a couple of options to avoid doing a new LocalCat()
:
Option #1
public class LolCatRepository : ILolCatRepository
{
public ILolCat Get(Guid id)
{
return NinjectHelper.Resolve<ILolCat>();
}
}
Ninject is setup as follows:
Bind<ILolCat>().To<LolCat>();
And helper will be something like:
public static class NinjectHelper
{
public static T Resolve<T>()
{
IKernel kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
return kernel.Get<T>();
}
}
Option #2 is a bit cleaner and uses constructor injection:
public class LolCatRepository : ILolCatRepository
{
public List<ILocalCat> _localCats;
// ninject will inject this list due to the chain of dependency.
// if it fails, then go with option #1.
public LolCatRepository(List<ILocalCat> localCats)
{
this._localCats = localCats;
}
public ILolCat Get(Guid id)
{
return this._localCats.FirstOrDefault(lc => lc.Id == id);
}
// similarly GetAll
}