I'm still gaining experience in dependency injection. I created a new console app project and added two other projects to mimic a real world app. So the three projects in my app are:
- MyConsoleApp
- MyBusinessService
- MyDataRepository
I created all my interfaces so that MyBusinessService is only using interfaces to get data from the repository.
My question is about MyConsoleApp. As I understand it, this is where Ninject will resolve all the dependencies.
Two questions:
- I think this means MyConsoleApp will have to reference both MyBusinessService and MyDataRepository. Is this correct?
- I think, in MyConsoleApp, I'll have to "manually" bind the IMyDataRepository interface to MyDataRepository concrete class -- see code below. Is this correct? I get a bit confused here because in some tutorials, they're mentioning that Ninject will resolve dependencies "automatically".
I think my code will look like this:
static void Main()
{
// Get Ninject going
var kernel = new StandardKernel();
// Bindings
kernel.bind<IMyDataRepository>().To<MyDataRepository>();
// Some business logic code my console app will process
}