Question

Say I have the following layered architecture...

enter image description here

I want to implement an aspect that requires some form of data access. Each of the projects in the stack have reference to the aspect framework. Therefore I cannot have the aspect assembly reference the data access layer due to circular references.

So how should I go about doing data access within the aspect?

Was it helpful?

Solution

This is solved using run-time dependencies.

Best approach for this is inversion of control pattern.

Your data access may implement interfaces and their implementation may be retrieved during run-time by resolving who implements the whole interface using an inversion of control framework like Castle Windsor or Ninject.

Your aspects will interact with the data layer with the whole interfaces instead of design-time references, thus you'll avoid compile-time circular references.

I'd like to add some clarification: run-time dependency resolving isn't a silverbullet to produce circular reference that avoid compile-time errors.

Sometimes your implementations may be part of an assembly that once referenced in design-time may end in a circular reference, but this is just a coincidence: it may be in that assembly or in a implementations-only one, or just a third-party assembly. Who knows ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top