简体   繁体   中英

Structuring a playframework application

I am new to playframework, so although this might be a newbie question, I need to ask. I have an application, where the database data can be changed by web requests, as well as by incoming emails.

I know that controllers are primarily used for web requests. Therefore, should I encapsulate the model modification logic in a separate class, which I should call from both the controller, and the guy who accepts the emails. Is this what the Service paradigm is used for?

Second, what should I use for the mail acceptor. A job or a plugin? Currently I created a job which refreshes itself every 10 seconds, but didn't know if it is appropriate to use a job to modify the DB. Perhaps, the job can trigger an internal event which a plugin will listen for ...

Yes you can update the model throught a job, job are transactionals.

For your common logic, if it relates to a specific model object, you can use a method on this object to put your common logic : put in static methods every code that is not tied to a specific instance and in non static methods logic that is tied to a specific instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM