Question

I'm reading through Mark Seeman's Dependency Injection in .NET (excellent read so far) and something is...

I'm reading through Mark Seeman's Dependency Injection in .NET (excellent read so far) and something is escaping me.

If the application's architecture is like [DAL] => [BLL] <= [UI], with the Business Logic Layer free of dependencies upon Data Access and UI layers (and both dependent upon the BLL), and if the composition root is located in the UI layer, then how on Earth are we supposed to be able to bind the interface of a type in the BLL with an implementation that's in the DAL?

Mark Seeman gives a nice, typical example: abstract class ProductRepository lives in the BLL and class SqlProductRepository in the DAL. This may sound like a silly question but how is the UI layer supposed to be able to bind ProductRepository to SqlProductRepository without a reference to the DAL?

I move all the Controllers and ViewModels from the User Interface Layer to the Presentation Model layer, leaving only the Views (the .aspx and .ascx files) and the COMPOSITION ROOT in the User Interface layer.

Thing is, I'm pretty sure this guy knows what he's talking about, so what part have I missed?

Also where would I have to put the composition root in the case of a class library project? At first I thought the BLL would be perfect (given [DAL] <= [BLL] => [UI]), but now that I've refactored my project to literally reverse the dependencies, I don't know anymore - I used to have a BLL that knew about both the DAL and the UI layer so binding the types of these layers was easy, now nobody knows about everyone anymore, it's like I don't have anywhere I could possibly put a composition root. Help me out here, I feel like I'm missing a fundamental cornerstone...

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Just create a Bootstrapper project in your UI layer. This is were the binding between your BLL interfaces and your concrete implementation will be defined.

Have a look at this SO answer where I explain all the steps to let it work.
It's an Onion architecture related question but things are almost the same here.

Last thing to mention is that if you have Internal services that your Bootstrapper project have to know about, edit the AssemblyInfo.cs file of your BLL project and allow Bootstrapper to see its Internal types as follows: [assembly: InternalsVisibleTo("Bootstrapper")]

Add a comment
Know the answer?
Add Answer to:
I'm reading through Mark Seeman's Dependency Injection in .NET (excellent read so far) and something is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT