CS FundamentalsVery hardProduct-company placement
A dependency-injection container registers ReportCache as a singleton, and ReportCache takes a DbSession in its constructor; DbSession is registered as scoped (one per HTTP request). What goes wrong?
- A. Each request gets a fresh ReportCache
- B. The container rejects all singletons that have dependencies
- C. The singleton captures the first request's DbSession and keeps using it for every later request, after that request's scope ended
- D. Nothing; the container substitutes a new DbSession for every method call
Correct answer: C. The singleton captures the first request's DbSession and keeps using it for every later request, after that request's scope ended
A longer-lived object holding a shorter-lived dependency keeps it beyond its intended lifetime (a captive dependency), giving stale or disposed sessions and cross-request data leaks. Inject a factory or make the consumer scoped; some containers detect this at start-up.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- Counting each if, loop header, and/or operator, conditional expression and except clause as one decision (V(G) = decisions + 1), what is…
- A function has three if-else statements in sequence, followed by a loop that runs either 0 or 1 time (decided by the input) and whose body…
- For a function of two independent bounded inputs, match each boundary-value technique with the number of test cases it needs. P. Normal…
- A decision table has three yes/no conditions and four rules: R1: C1 = N (C2, C3 don't care) → A; R2: C1 = Y, C2 = N (C3 don't care) → B…
- A state machine has transitions a: S1→S2, b: S2→S3, c: S3→S1 and d: S2→S1. How many test items does 0-switch (every transition) coverage…
- How many of these statements about data-flow coverage criteria are correct? 1. All-uses subsumes all-defs (when every definition reaches…