---
title: "Comment by JS Rammohan on \"SOLID Principles in Spring Boot: A Comprehensive Guide\" | Hashnode"
description: "First of all, thanks for the detailed explanation about solid principles usage. I have a question about how to initialize runtime object of PaypalPaymentService"
url: "https://hashnode.com/posts/solid-principles-in-spring-boot/63e77d3200ce505f786e81f1/comment/660cafe4e3f49ff8760c16aa"
---

[Discussion](https://hashnode.com/posts/solid-principles-in-spring-boot/63e77d3200ce505f786e81f1)

Comment [SOLID Principles in Spring Boot: A Comprehensive Guide](https://hashnode.com/posts/solid-principles-in-spring-boot/63e77d3200ce505f786e81f1)

[JS Rammohan](https://hashnode.com/@Ram1603)

[Apr 3, 2024](https://hashnode.com/posts/solid-principles-in-spring-boot/63e77d3200ce505f786e81f1/comment/660cafe4e3f49ff8760c16aa)

First of all, thanks for the detailed explanation about solid principles usage. I have a question about how to initialize runtime object of PaypalPaymentService for Rest Controller in DIP example.

[Amr Khaled](https://hashnode.com/@amrkh97)

[Apr 21, 2024](https://hashnode.com/posts/solid-principles-in-spring-boot/63e77d3200ce505f786e81f1/comment/660cafe4e3f49ff8760c16aa#reply-6624d42bdf20e2b36f0001bc)

Thank you so much, and sorry for the very late reply.

You can initialize it in multiple ways:

1- Constructor injection:

private final PaymentService creditCardPaymentService; private final PaymentService payPalPaymentService;

@Autowired public PaymentController(CreditCardPaymentService creditCardPaymentService, PayPalPaymentService payPalPaymentService) { this.creditCardPaymentService = creditCardPaymentService; this.payPalPaymentService = payPalPaymentService; }

2- With qualifiers:

@Qualifier("payPalPaymentService") public class PayPalPaymentService extends PaymentService {

and then in your controller or other service:

private final PaymentService creditCardPaymentService; private final PaymentService payPalPaymentService;

@Autowired public PaymentController(@Qualifier("creditCardPaymentService") PaymentService creditCardPaymentService, @Qualifier("payPalPaymentService") PaymentService payPalPaymentService) { this.creditCardPaymentService = creditCardPaymentService; this.payPalPaymentService = payPalPaymentService; }
