0

I'm architecting a new App and I really unconfortable with this approach in ASP.NET Core that made "normal" adding a DbContext by using AddDbContext, in services.

I'd like to know if you guys think that using AddDbContext in ASP.NET Core isn't a bad practice, since it forces my Web App to have a dependecy on my database access layer.

I've researched a lot and it was incredible that there isn't almost anything that cover this subject.

How should I proceed to overcome this concern?

Thanks!

1 Answer 1

4

it forces my Web App to have a dependency on my database access layer

That's exactly the place where it should be: the composition root. Your application startup code is the place where you glue your components together.

What else would you want, create a separate library, containing interfaces for all classes in your entire DAL, and wire that up using magic during startup?

Sign up to request clarification or add additional context in comments.

1 Comment

OK. Maybe I don't really understand what does it mean. But in a simple 3-tier app, for instance, I shouldn't have web, service and data layer, on which web gets its data through service layer, and service gets its data from data layer (which actually contains dbcontext reference)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.