❔ Why "Controller’s methods calls the infrastructure layer" is a bad practice?
I received this feedback in a technical assessment. The program was a ASP.NET Core API. I had a Repository layer calling Entity Framework. The repositories were injected in the controllers and from there I called repositories methods. For example, I called a "CanPost" method that would determine the rest of the workflow in the controller.
What should I have done instead? Thanks
9 Replies
Maybe build a service repository pattern?
what?
that doesn't even make sense
you're specifically not calling the "infrastructure" directly within controllers, you're using a repository layer in between
what the hell is "infrastructure layer" supposed to mean, then?
maybe I'm just missing context by not having the code to look at?
regardless, the only way that kinda comment REALLY makes sense is in the context of an existing application where the architecture is already well-define, and your code simply didn't follow it well
I.E. the only way to answer "what's wrong with this" is to compare it to the existing architecture of that application
which isn't something anyone here can do
saying that "Controller's methods calls the infrastructure layer" is bad practice universally is just flat-out wrong
There was no previous architecture, I was free to create my own
This is the piece of relevant code
Hey @ReactiveVeina can a microservice call another microservice without calling Gateway?
given that all of those terms can mean almost anything, I'd have to say "yes"
two things
A) it's unclear from just looking at this whether you're doing pagination in memory, or on the database. If it's being done in-memory, that's definitely bad
B) there's nothing fundamentally wrong with this setup, so long as it's consistent with the rest of the app
I was doing pagination in memory, this was another bad point
But I'm able to understand and fix
I guess addind a Service layer on top of the repository is what the reviwer was expecting
Thanks
yup adding a service layer will give you chance to add logger later on to see what went wrong while calling microservice
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.