We're using Ninject for IOC.
All of our Repository objects can (and should be) mocked for unit testing. I'd like to enforce that all developers code only to interfaces when interacting with Repositories. For this, I'd like to make the constructors private and create static accessor factory methods for construction:
public class SomeRepository : ISomeRepository
{
private SomeRepository()
{
}
public static ISomeRepository Create()
{
return StandardKernel.Get<ISomeRepository>();
}
}
Problem lies in this: how do I have Ninject create the actual object? I have repository interface and class in the same project
StandardKernel.Get
looks like a Service Locator from here. I won't say "Service Locator is definitely wrong here", but Mark Seemann would, and I would trust him over me if I were you. – default.kramerSomeRepository
use the kernel? Isn't the idea of IoC forSomeRepository
not to have to constrcut or load it's own dependencies? I agree code reviews is the way to go to ensure all developers use the kernel as required. – Nope