Create modules in Play Framework


#1

Hi,

I want to develop my application with play framework. This is very extensive and I would like to develop it by modules (modular application). I think it is the best way to do it and easier to administer the system in the future. Also my team will be able to develop the independent modules and then add them to the application.

I have been looking at the documentation about how to create modules using Java(https://www.playframework.com/documentation/2.7.x/JavaPlayModules) but it is not clear to me how to do it.

do you know how to do it? or do you know any tutorials that I can follow?

Thanks and Regards


(Marcos Pereira) #2

I think that what you want are subprojects:

https://www.playframework.com/documentation/2.7.x/SBTSubProjects#Working-with-sub-projects

Unless you really want to create some modules (in the sense of dependency injection modules) that you can publish and later add to your project.

Best.


#3

Thanks @marcospereira
It looks good and you may be right. I’m going to do some tests and I’ll tell you.

As I understood subprojects are easier to administer than modules and can be share common variables and code. It isn’t possible with modules because modules are independent. Modules are useful if we want use this part in multiples applications because only have a module sharing multiples applications at the time of administration, we only have to make a change once and not in each subproject that we use.

Is the idea I have about modules and subprojects correct?

Thanks


#4

Hi all,

I’m using subprojects but I have a couple of doubts.

The first is if I have for example an application with 3 subprojects (login, user, products) and I need to create another application, could I reuse for example login and user? (Or for this reason is it better to use modules?)

The other question is the following. For example, I have a subproject called login, and when a user logs in correctly, he goes to see his account (this is the user subproject). How can I call from the login controller to the user? this way I get error

return redirect(
controllers.user.routes.UsersController.home()
);

Finally, do you know what is a good code structure to follow in the play framework for big applications? Maintenance in big applications is laborious and even more so when a confusing structure is used, that is why the structure of the code is very important. I use the following but I do not know if it is the best: