tessl install github:giuseppe-trisciuoglio/developer-kit --skill spring-boot-dependency-injectiongithub.com/giuseppe-trisciuoglio/developer-kit
Dependency injection workflow for Spring Boot projects covering constructor-first patterns, optional collaborator handling, bean selection, and validation practices.
Review Score
67%
Validation Score
10/16
Implementation Score
85%
Activation Score
33%
This skill captures the dependency injection approach promoted in this repository: constructor-first design, explicit optional collaborators, and deterministic configuration that keeps services testable and framework-agnostic.
@Service, @Component, or @Repository classes.@ServiceConnection../gradlew test or mvn test for validation../references/ when deeper patterns or samples are required.@Autowired members, and configuration classes.@RequiredArgsConstructor) that accept every mandatory collaborator.final and protect invariants with Objects.requireNonNull if Lombok is not used.@Configuration or @Bean factories to pass dependencies explicitly; consult ./references/reference.md for canonical bean wiring.@Autowired(required = false) or inject ObjectProvider<T> for lazy access../references/examples.md#example-2-setter-injection-for-optional-dependencies for a full workflow.@Primary for dominant implementations and @Qualifier for niche variants../references/reference.md#conditional-bean-registration for conditional and profile-based samples.@WebMvcTest, @DataJpaTest, @SpringBootTest) only after constructor contracts are validated../references/reference.md#testing-with-dependency-injection to select the proper test style.@Service
@RequiredArgsConstructor
public class UserService {
private final UserRepository userRepository;
private final EmailService emailService;
public User register(UserRegistrationRequest request) {
User user = User.create(request.email(), request.name());
userRepository.save(user);
emailService.sendWelcome(user);
return user;
}
}new UserService(mockRepo, mockEmailService); with no Spring context required.@Service
public class ReportService {
private final ReportRepository reportRepository;
private CacheService cacheService = CacheService.noOp();
public ReportService(ReportRepository reportRepository) {
this.reportRepository = reportRepository;
}
@Autowired(required = false)
public void setCacheService(CacheService cacheService) {
this.cacheService = cacheService;
}
}CacheService.noOp() to ensure deterministic behavior when the optional bean is absent.@Configuration
@Import(DatabaseConfig.class)
public class MessagingConfig {
@Bean
@ConditionalOnProperty(name = "feature.notifications.enabled", havingValue = "true")
public NotificationService emailNotificationService(JavaMailSender sender) {
return new EmailNotificationService(sender);
}
@Bean
@ConditionalOnMissingBean(NotificationService.class)
public NotificationService noopNotificationService() {
return NotificationService.noOp();
}
}@Import, profiles, and conditional annotations to orchestrate cross-cutting modules.Additional worked examples (including tests and configuration wiring) are available in ./references/examples.md.
@Autowired on single constructors.null pointers.@Lazy usage to performance-sensitive paths and record the deferred initialization risk.spring-boot-crud-patterns – service-layer orchestration patterns that rely on constructor injection.spring-boot-rest-api-standards – controller-layer practices that assume explicit dependency wiring.unit-test-service-layer – Mockito-based testing patterns for constructor-injected services.