📊 Scope Vergleich

Alle Scopes auf einen Blick

← Zurück zur Übersicht

🎯 Was siehst du hier?

Diese Seite zeigt alle Scopes gleichzeitig an. Reload die Seite mehrmals und beobachte, welche Counter sich ändern und welche gleich bleiben!

Pro-Tipp: Öffne die Seite in verschiedenen Tabs und im Inkognito-Modus, um die Unterschiede zwischen den Scopes zu verstehen!

🔵 Singleton Scope

Singleton Info

Erwartung: Counter steigt bei JEDEM Reload, egal welcher Tab!

🟡 Request Scope

Request Info

Erwartung: Counter ist immer 1, neue ID bei jedem Reload!

🟣 Session Scope

Session Info

Erwartung: Counter steigt in derselben Session, neue ID in Inkognito!

🔴 Application Scope

Application Info

Erwartung: Counter steigt für ALLE User, gleiche ID überall!

🧪 Experimentier-Guide

Experiment 1: Reload im selben Tab

Experiment 2: Neuer Tab (gleiche Session)

Experiment 3: Inkognito-Modus (neue Session)

📚 Wann nutze ich welchen Scope?

Scope Use Cases Vorsicht bei...
Singleton • Services
• Repositories
• Stateless Beans
• Configuration
• Mutable State
• Thread-Safety!
• Instance Variables
Prototype • Commands
• Stateful Objekte
• Tasks
• DTOs mit Logic
• Memory-Leaks
• Expensive Objects
• @PreDestroy läuft nicht!
Request • Request-Daten
• User Input
• Request Context
• Temporary Data
• Nur in Web-Apps!
• ProxyMode nötig
• Performance
Session • User-Daten
• Shopping Cart
• Preferences
• Login State
• Memory Usage!
• Session Timeout
• ProxyMode nötig
Application • Global Counters
• App-wide Cache
• Statistics
• Shared Config
• Thread-Safety!
• ProxyMode nötig
• Ähnlich wie Singleton

💡 Key Takeaways