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.
L2J and Dependency Injection
Forum rules
READ NOW: L2j Forums Rules of Conduct
READ NOW: L2j Forums Rules of Conduct
- Zoey76
- L2j Inner Circle
- Posts: 7008
- Joined: Tue Aug 11, 2009 3:36 am
L2J and Dependency Injection
Powered by Eclipse 4.34
| Eclipse Temurin 21
| MariaDB 11.3.2
| L2J Server 2.6.3.0 - High Five 
Join our Discord! 

- jurchiks
- Posts: 6769
- Joined: Sat Sep 19, 2009 4:16 pm
- Location: Eastern Europe
Re: L2J and Dependency Injection
Some of these injections look like they'd reduce CPU usage and speed of access (`DAOFactory.getInstance().getXDAO()`) and, conversely, potentially slightly increase memory usage due to persistent in-memory references that these calls avoided. No idea which is better, but I'd probably go for reduced CPU usage since RAM is cheap and plentiful these days.
However, some seem to be pointless (injecting an instance of a class when only static methods of that class are used). That's essentially an unused instance.
However, some seem to be pointless (injecting an instance of a class when only static methods of that class are used). That's essentially an unused instance.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
- Zoey76
- L2j Inner Circle
- Posts: 7008
- Joined: Tue Aug 11, 2009 3:36 am
Re: L2J and Dependency Injection
Agreed, that not all would benefit right away, this is not really about CPU or RAM, it's about design and extensibility, you can neglect most of this injection costs.jurchiks wrote: โMon May 04, 2020 12:26 am Some of these injections look like they'd reduce CPU usage and speed of access (`DAOFactory.getInstance().getXDAO()`) and, conversely, potentially slightly increase memory usage due to persistent in-memory references that these calls avoided. No idea which is better, but I'd probably go for reduced CPU usage since RAM is cheap and plentiful these days.
However, some seem to be pointless (injecting an instance of a class when only static methods of that class are used). That's essentially an unused instance.
Powered by Eclipse 4.34
| Eclipse Temurin 21
| MariaDB 11.3.2
| L2J Server 2.6.3.0 - High Five 
Join our Discord! 

- nonom
- L2j Veteran
- Posts: 649
- Joined: Wed Mar 11, 2009 10:34 pm
- Location: Magmeld
Re: L2J and Dependency Injection
I was using DI with PHP which is also awesome to decouple for testing. Sounds great.
-
- Posts: 21
- Joined: Thu Aug 29, 2019 5:54 pm
Re: L2J and Dependency Injection
Great work!
Keep it coming

-
- Posts: 1
- Joined: Tue Apr 26, 2022 11:49 pm
Re: L2J and Dependency Injection
Although this is an old thread I must say that adding DI is a big step forward. Specially if you aim for TDD. I honestly don't know how you can test the code now.
Aside from TDD, you could also be interested in DDD. I think it could be pretty good for this kind of complex projects.
Aside from TDD, you could also be interested in DDD. I think it could be pretty good for this kind of complex projects.
-
- Posts: 1
- Joined: Fri Jan 06, 2023 7:51 pm
Re: L2J and Dependency Injection
Hi,
A few of these infusions see like they'd decrease CPU utilization and speed of get to alternately, possibly somewhat increment memory utilization due to diligent in-memory references that these calls dodged. No thought which is superior, but I'd likely go for diminished CPU utilization since Slam is cheap and ample these days. However, a few appear to be inconsequential (infusing an occasion of a lesson when as it were inactive strategies of that course are utilized). That's basically an unused occurrence.thanks! i am working on furniture.
A few of these infusions see like they'd decrease CPU utilization and speed of get to alternately, possibly somewhat increment memory utilization due to diligent in-memory references that these calls dodged. No thought which is superior, but I'd likely go for diminished CPU utilization since Slam is cheap and ample these days. However, a few appear to be inconsequential (infusing an occasion of a lesson when as it were inactive strategies of that course are utilized). That's basically an unused occurrence.thanks! i am working on furniture.
Australia Base project for https://www.aushoppinghub.com/ for Online Shopping of Furniture and Homewares.