2

I have a multi-tier console application with the following components: - data access layer - domain layer - uses data repository classes defined in the data access layer - engine - this contains the entry point for the application and uses the domain layer classes, orchestrating the operations

The data access layer classes and the domain layer classes implement a set of interfaces. How do you recommend that I do DI? Do I need a reference to Ninject in both my domain classes and my engine classes, is there any other way to do the binding in a single place? What would be the best pattern to do this.

I'm just starting out with DI and Ninject so any help, examples and explanations would be very helpful.

kjv
  • 11,047
  • 34
  • 101
  • 140

2 Answers2

3

I will write you a simple example and add it on my github. Should be there in 30 minutes or so. Will post the link to it here a.s.a.p

EDIT: Here you have the sample project: ConsoleApplicationNinject

EDIT: And this is where you´ll do the binding. https://github.com/codeplanner/ConsoleAppNinject/blob/master/ConsoleAppNinject/Ninject/ServiceModule.cs

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
Uffe
  • 2,275
  • 1
  • 13
  • 9
  • OK but note that activation blocks are deprecated http://www.planetgeek.ch/2012/04/23/future-of-activation-blocks/ You might find http://stackoverflow.com/a/15836383/11635 interesting – Ruben Bartelink Apr 09 '13 at 15:34
  • Ruben: did not know that. Ninject has poor (or well hidden) documentation. Anyway, it works and we use it with websockets since there is no requests cope there. Good to have your link for future reading. – Uffe Apr 09 '13 at 15:50
  • The activation blocks realisation is just a floating of an idea, and the NamedScope stuff (esp `CreateNamedScope`) is new. I'll shortly be doing PRs and/or docs in `Ninject.Extensions.NamedScope` for that custom request scoping stuff (and CreateNamedScope itself) - I have it in production now as pasted. Also https://github.com/ninject/ninject/wiki/Object-Scopes was recently updated and expanded with a lot of key bits of info – Ruben Bartelink Apr 09 '13 at 20:54
2

Do I need a reference to Ninject in both my domain classes and my engine classes, is there any other way to do the binding in a single place? What would be the best pattern to do this.

As close as possible to the application's entry point.

This place is called the Composition Root.

Steven
  • 166,672
  • 24
  • 332
  • 435