L2J and Dependency Injection
Posted: Mon May 04, 2020 12:05 am
Trying to improve L2J architecture, testability and overall design I have been experimenting with dependency injection in the core.
https://bitbucket.org/l2jserver/l2j-ser ... e6f2ec3cbd
I've used Spring Context (could have used Guice, but I may use more of the Spring Framework in the future), the basic idea is to create managed beans and avoid Singleton anti-pattern that we have favored so much in the past.
In this example server is configured to use a new application context and all DAOs are turned into injectable @Repository beans, also player loading and creation is segregated to a PlayerService class.
This @Autowire(d) components are not visible in datapack due compilation, need to experiment with AspectJ a little bit further to get it working.
Before moving forward on this approach, I'll work more on completing this DAO/Repository classes removing data access code from classes such as L2PcInstance.
I'd like to know what do you think about this approach, I believe it could help go towards TDD and more flexible and extensible Core implementation.
https://bitbucket.org/l2jserver/l2j-ser ... e6f2ec3cbd
I've used Spring Context (could have used Guice, but I may use more of the Spring Framework in the future), the basic idea is to create managed beans and avoid Singleton anti-pattern that we have favored so much in the past.
In this example server is configured to use a new application context and all DAOs are turned into injectable @Repository beans, also player loading and creation is segregated to a PlayerService class.
This @Autowire(d) components are not visible in datapack due compilation, need to experiment with AspectJ a little bit further to get it working.
Before moving forward on this approach, I'll work more on completing this DAO/Repository classes removing data access code from classes such as L2PcInstance.
I'd like to know what do you think about this approach, I believe it could help go towards TDD and more flexible and extensible Core implementation.