In a MVC web application, I often send emails.
I usually do it in the controller, as I load all my views from the controller (including email views).
Now, however, I have some code where the email sends from the model.
Which tier is email generally sent from? Does it matter? Does it need to be consistent?
Also, MVC relies heavily on reflection, which allows you to inspect types at runtime using strings. Reflection is used in many programming frameworks.
A controller, in a computing context, is a hardware device or a software program that manages or directs the flow of data between two entities. In computing, controllers may be cards, microchips or separate hardware devices for the control of a peripheral device.
In object-oriented programming development, model-view-controller (MVC) is the name of a methodology or design pattern for successfully and efficiently relating the user interface to underlying data models.
A controller should ideally be like an operator that connects a view to a model. This either belongs in the model or service layer.
I would argue that this belongs in the Model layer only if you have a model object that is solely responsible for sending e-mails. You don't want to comingle presentation and logic, that's the whole point of separation of concerns in Model-View-Controller.
This type of logic should reside in a service layer. You could then use dependency injection to inject the service into the controller and call EmailSenderService.sendEmail();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With