java - Non-managed objects in Spring application (best practice) -
i have been working on few web applications , rest web services (spring ioc/mvc/data jpa etc). follow same pattern: controller classes --> service classes (which have several "utility"/business logic classes autowired) --> spring data repositories.
pretty of classes above spring singletons. feel makes code , functions within class dirtier; example, can't have state in class, need pass lot parameters between methods, , don't having more 1-2 parameters (although know necessary).
i wondering how problem overcome in big (e.g. enterprise) kind of application.
- is common practice use non-spring managed classes in spring application? if so, how pass dependencies (the ones autowired)? if use constructor injection example, need autowire necessary dependencies class creates object , wanted avoid that. also, don't want messing load time weaving etc. autowire beans non-spring objects.
- is using prototype scoped beans solution? thing need use aop's scoped proxies (or method injection etc) make sure new instance bean autowired singleton in first place. "clean" , reliable option (i.e., there no concurrency type of issues)? can still autowire singletons classes no issues?
does worked on large system (and managed keep structure not "bloated" , clean) have recommendations? maybe there patterns not aware , use?
any appreciated.
spring designed, must not worry about ioc implementation of di. pattern have mentioned /controller layer -> service layer -> data access layer/ in practice, , ok these singleton objects not have state because of rule of oop: "think objects service providers 1 thing well". models can have state jpa units storing in database. not mandatory in large systems have dirty code how mentioned passing lot of parameters, depends on design decision need deeper construction.
Comments
Post a Comment