C
C#2y ago
big OOF

❔ Architecture

Hello, If you have a API-controller class with a GET method inside. Lets say the GET should return a math calculation that is done in the function ExampleFunction(). The GET inside the api-controller needs to call the ExampleFunction. So to my question, where should you place ExmapleFunction()? From what i understand: - Not in the API controller - Maybe inside a service class? - Create a "general methods class"? Thanks in advance 🙂
5 Replies
ChucklesTheBeard
Generally speaking, a "general methods" class, aka a util class, is a code smell; on its own, maybe not the worst thing in the world... but being unable to name it something more specific may be a red flag showing it's violating the single responsibility principle. Where the function should go depends on what the calculation is and why it needs to be done server-side.
big OOF
big OOF2y ago
@ChucklesTheBeard okey thanks! A follow-up question, i have a model class that I'm using when dezerializing retrieved JSON from an API. From what i understand you never write function into the model class? - It should only contain the model 🙂
ChucklesTheBeard
I'm confused regarding what architecture you're using, that would prohibit putting a function in a model or a controller...
Angius
Angius2y ago
Generally, yes, DTO classes consist of just the properties
Accord
Accord2y ago
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.