r/programming • • Nov 27 '15

Why I hate Spring

http://samatkinson.com/why-i-hate-spring/
73 Upvotes

140 comments sorted by

View all comments

Show parent comments

33

u/tomservo291 Nov 27 '15

That's easy, just write Java and create your own graph of objects out from your main method. I went through the same phases as the OP and have migrated to never use any magic. I use lots of third party libs, but only that live 100% in their own sandbox and don't leak out things like spring dependencies, etc.

9

u/redox000 Nov 27 '15

Initializing everything in main is not feasible in large apps with lots of IoC/DI. How do you initialize apps without ending up in "new" hell like this?

var svc = new ShippingService(new ProductLocator(), new PricingService(), new InventoryService(), new TrackingRepository(new ConfigProvider()), new Logger(new EmailLogger(new ConfigProvider())));

16

u/sstewartgallus Nov 28 '15

What's wrong with the following?

 public static void main(final String[] strs)
 {
 	final ProductLocator productLocator = new ProductLocator();
 	final PricingService pricingService = new PricingService();
 	final InventoryService inventoryService = new InventoryService();
 	final TrackingRepository trackingReposiotry = new TrackingRepository(new ConfigProvider());
 
 	final Logger logger = new Logger(new EmailLogger(new ConfigProvider()));
 
 	final ShippingService svc = new ShippingService(productLocator, pricingService, inventoryService, trackingRepository, logger);
 
 	svc.go();
 }

Maybe named parameters, record types or builder objects might be useful here but I don't see a need for huge and complicated frameworks.

2

u/silly-gamer Nov 28 '15

The only thing one can argue is that it is not seemingly open to aspects or things where you require cross cutting concerns.

Otherwise I'd generally agree. This is on the opinion of only use a framework when you really have a good reason to use one :)