-1

I'm coming to build new "Enterprise solution"

So i decided to use "Onion Architecture" because i wanna as much as flexible architecture.

But I'm new to "Dependency Resolution" concern.

As I understand I should put Factories "Implementations" in this Layer and this layer has references to all other layers.

Then I wanna know how to make new instance of IFactory in the "UI Layer" when the FactoryImplementation in DependencyResolution Layer and UI Layer don't have reference to "DependencyResolution Layer"


Edit::

Thanks to Mr. Erik

But after I saw many of these links I still have problem when i want to "Register" Implementations to their "Interfaces" because I can't do something like this in UI Project:

kernel.Bind<ITaxCalculator>()
      .To<TaxCalculator>()
      .WithConstructorArgument("rate", .2M);

Because UI Project can't access TaxCalculator "Implementation".

Wahid Bitar
  • 13,776
  • 13
  • 78
  • 106

1 Answers1

5

I think the best solution would be to use a Dependency Container (aka IOC container) to resolve your references, such as Castle Windsor or Unity if you're on .NET. They make you able to configure up the dependency resolution without references to the actual implementations in the UI layer.

EDIT: Some links:

Community
  • 1
  • 1
Erik A. Brandstadmoen
  • 10,430
  • 2
  • 37
  • 55
  • +1 Thank you but UI project hasn't reference to Implementation Project Then how could i make "Resolving" if I can't reach "Implementation" in UI Project – Wahid Bitar Aug 23 '11 at 21:31
  • This is what DI containers can solve for you. You can do this in config files in some DI containers (no hard references there), for example. Wouldn't that solve your issue? – Erik A. Brandstadmoen Aug 23 '11 at 21:38
  • I think so if I could access external Library from "config" file. Please advice me which DI container to use and if possible with Example. – Wahid Bitar Aug 23 '11 at 21:56
  • 1
    There are of course different preferences here, and I cannot decide for you :). However, Castle Windsor should be well-tested and acknowledged. You can see an example on how to use config for configuring the Interface-to-class mapping here: http://docs.castleproject.org/Windsor.XML-Registration-Reference.ashx – Erik A. Brandstadmoen Aug 23 '11 at 22:00