php - Where do services go in MVC? -
i've asked several developers, , gotten different answers every time.
let's i'm working in mvc framework , have class called validator
. object has bunch of methods can used tell if email or phone number valid, or if given value has content in it.
say want make service property of model i'm creating. can inject construction method of model class. however, service fit in in mvc? model?
where should file stored? models? in it's own directory, perhaps called services
?
i think have different view [sadly no pun intended] of model in mvc, services should go in model layer.
first, model shouldn't class. model a model, of one application. application modelized in different things (contained in model layer): entities, mappers, services.
for exemple, file hierarchy representing concept:
application controller model entities mappers services view
say want make service property of model i'm creating. can inject construction method of model class. however, service fit in in mvc? model?
i'll assume "model" indeed entity
, object representing domain concept. in case, service should not property of entity. services should used controllers, whatever called do, mappers construct entities result of services did.
my current understanding vastly comes this answer, should read further understanding.
Comments
Post a Comment