views:

76

answers:

1

Please first read the following thread:

http://stackoverflow.com/questions/924382/circular-reference-between-assemblies-in-c-and-visual-studio-2005

Implementing interfaces is solving my problem but not fulfilling my target.

My target is to work only with BO-layer/assembly from the UI layer/Assembly. So that I can maintain a clean layer-to-layer reference.

Coz I don't want a reference to be added both for BO-layer/assembly and ORMapper-layer/assembly in the UI-layer/assembly.

I only want to work with BO-layer/assembly from within UI-layer/assembly.

Meanwhile someone suggested me that, it can only be possible with using Reflection, not DI. Is that true?

A: 

If you really insist on hiding the ORM layer behind your BO layer, then Dependency Injection should still be able to help you out. Note that you will not be able to get away from referencing the DI library from your UI thread though, because that'll be where your business objects will come from then.

Approach:

  • Create an interface that contains methods to load the data to populate User objects
  • Implement this interface in your ORM project
  • At start-up, register the ORM implementation against the interface using a DI container of some sort (read up the details on whatever DI library you use, for example: www.ninject.org for something lightweight)
  • Give the User object a constructor that takes an instance of the population interface to load data from

Then when you need a User object, you ask the DI library to create it, and the DI library will construct the User and give it a reference to the ORM implementation. You'll have to inject some properties into the DI call as well for the 'username' and 'password' to be able to fully populate it with values.

Note that this is not exactly what DI was invented for... application code is really supposed to deal with ORM directly to create/read/update/delete business objects.

jerryjvl
I'm looking forward to better solutions, but this is the best I can come up with right now.
jerryjvl
Thanks a lot Jerry! It really tickled my thought.