I am new to Spring Boot and still trying to grasp best practices. What attracted me was Spring Cloud Configuration. Initially I wanted to do a hybrid implementation (due to the size of the existing code base) of Spring Boot but it inevitably lead me to a bunch of code smell and anti-patterns.
Before Spring, I was managing my own objects but I've quickly realized that Spring wants full control of object instantiation and ownership where there is dependency injection (which I understand). However there are some cases where I cannot let Spring completely drive but still have a dependency on configuration (e.g. another framework responsible for object management).
I don't want to do a one off scenario where I end up passing configuration through a chain of constructors and I want to avoid using AutowireCapableBeanFactory::autoWireBean(...)
to manually wire my beans. At the same time, relying on Spring to manually initialize all my objects is a nuisance. To be clear, this is what I am talking about:
@SomeOtherFrameworkThatOwnsThisObject
@Configuration
public class SomeClassDeepInMyProject implements SomeKindOfInterface {
@Autowired
private ConfigurationController config;
...
}
I considered creating a singleton configuration provider that is accessible application wide and manually wiring the configuration bean to the class. If there is a better alternative, I am all ears.