Play app architecture

55 views
Skip to first unread message

Matt

unread,
Jun 1, 2015, 9:59:43 PM6/1/15
to play-fr...@googlegroups.com
Hello,

I'm just getting started with a private project and struggle on how to layout my app.
I haven't used Play or any Scala related framework before but am quite experienced in Java and all it's common frameworks (Spring, Hibernate, ....).

I already got a simple Play app (2.3) to work using Slick, ReactiveMongo and SecureSocial but all classes are a complete mess.
My UI app is a separate project and is (to be) written in Angular, skeleton is done and it integrates with the backend..

In terms of architecture for a Java Web Application it's usually pretty straight forward as you separate the layers in UI/Controller, Service, DB Abstraction or a similar variance.
In Play I'm a little lost on how to best separate those, both Play-ReactiveMongo and Play-Slick promote the idea to directly access the DB from within the Controller, am I missing the point here or is this the Play Way?
I don't like to directly access the DB from the controller so I created some classes to separate concerns, Service and Repository in particular.
My repository contains the Slick Table definition of the domain object/case class, the service gets the repo injected and wraps the table access in needed methods like list, get, save, .... and calls out to other services.
Am I working against the Play Way or is this an eligible way of doing things in Play?

One issue I have since I upgraded to 2.4 and switched over to DI (used the Cake pattern for a few classes before) is that I created the schema in the Global object using Slick's table.schema.create.
As I'm wrapping the table in the repo and the service I'd have to inject the service into the Global object to avoid direct access to the table?
As there's no Singleton in the Java language creating Singleton beans with a DI framework seems like a good solution, now, with Scala, I feel like I'm using it wrong if I change the object Global extends GlobalSettings over to be a class to inject a required dep. via the constructor, any recommendations on how to separate those layers and any tips on dependency injection and the usage of Objects in Scala would be greatly appreciated.

Thanks and best regards
Matt
Reply all
Reply to author
Forward
0 new messages