To be honest, anyone wishing for Atiku to become our President didn't mean well for Nigeria.
Hear him with your ears👇👇
“I will enrich my family and friends. Are my friends not entitled to be rich under my Presidency?" ~Atiku..
May Atiku Abubakar never happen to Nigeria.
Should you abstract away EF Core in Clean Architecture?
The typical arguments to support this are:
- Easier to change the database later
- Not leaking external concerns
- Easier to unit test
But when was the last time you changed the database on any project?
Probably never.
❌ Unit testing a database is a bad idea.
✅ Write integration tests.
Clean Architecture emphasizes the separation of concerns by dividing an application into layers.
You want most of the business logic in the Application and Domain layers.
If you're being dogmatic, you shouldn't introduce database concerns in the Application layer.
So, you decide to hide EF Core behind a repository interface.
Abstracting away EF Core with Clean Architecture seems like a good idea at first.
But it can lead to more problems down the road.
By abstracting away EF Core, you are creating an abstraction on top of an abstraction.
This adds unnecessary complexity to your codebase.
Besides, Clean Architecture provides flexibility and adaptability to your application.
Instead of abstracting away EF with Clean Architecture, why not embrace it?
You can use the powerful EF features to your advantage.
Here's a "hacky" solution I often see.
You create an IApplicationDbContext abstraction.
It's an interface for the EF DbContext.
It doesn't depend on the concrete EF provider, only the base library.
If you're using CQRS with MediatR, you may want to use EF for queries.
But you're still leaking EF to the Application layer.
I have a simple fix for this problem - move the query handlers.
The query handlers are implementation details. Right?
So you can move them to the Infrastructure layer and use EF directly.
That way, the Application layer doesn't need to reference EF.
P.S. If you liked this, consider joining The .NET Weekly - my newsletter with 35,000+ engineers that teaches you how to improve at .NET and software architecture.
Join 35,000+ engineers here → https://t.co/2kGSP2ufoa
What do you think about abstracting away EF Core?
What architecture should you use with Modular Monoliths?
Here are 3 options to choose from:
- Clean architecture
- Layered architecture
- Vertical slice architecture
Of course, you could use anything else.
I'm only giving you a few examples to start with.
But the point I'm making is modular monoliths are flexible.
Let's say you have 3 modules in your application.
You can decide to structure each module differently.
One module is a simple CRUD application. I don't benefit from using Clean architecture for this module. I can use a simple layered architecture with two layers.
Another module has complex business logic. I've used DDD before to solve problems like this. Clean architecture and DDD work well together. This is what I chose for this module.
I'm not saying go and use every software architecture you know.
But also, don't be dogmatic and use the same architecture for all modules.
You should approach each module in a modular monolith like a separate application. In general, the modules should be self-contained and isolated.
Use the best solution for the problem you're currently solving.
And be ready to adopt a new approach if it offers an advantage.
P.S. If you liked this, consider joining The .NET Weekly - my newsletter with 35,000+ engineers that teaches you how to improve at .NET and software architecture.
Subscribe here → https://t.co/2kGSP2ufoa
What do you think about the Modular monolith architecture?