0
0
LLDsystem_design~10 mins

Dependency injection framework in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a dependency injection container.

LLD
container = [1]()
Drag options to blanks, or click blank then click option'
AServiceLocator
BDIContainer
CInjector
DProvider
Attempts:
3 left
💡 Hint
Common Mistakes
Using ServiceLocator instead of DIContainer
Confusing Injector with container
2fill in blank
medium

Complete the code to register a service class in the container.

LLD
container.[1](MyService)
Drag options to blanks, or click blank then click option'
Aadd
Bprovide
Cbind
Dsingleton
Attempts:
3 left
💡 Hint
Common Mistakes
Using bind which may create new instances
Using add which is not a standard method
3fill in blank
hard

Fix the error in the code to retrieve a service instance from the container.

LLD
service = container.[1](MyService)
Drag options to blanks, or click blank then click option'
Aresolve
BgetInstance
Cfetch
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using getInstance which is not standard here
Using create which may instantiate new objects incorrectly
4fill in blank
hard

Fill both blanks to define a service with constructor injection.

LLD
class MyController:
    def __init__(self, [1]):
        self.service = [2]
Drag options to blanks, or click blank then click option'
Aservice
Bself.service
CMyService()
Dservice()
Attempts:
3 left
💡 Hint
Common Mistakes
Calling service as a function
Assigning MyService() directly inside constructor
5fill in blank
hard

Fill all three blanks to register and resolve a service with dependencies.

LLD
container.[1](MyRepository)
container.[2](MyService, lambda: MyService([3]))
Drag options to blanks, or click blank then click option'
Aregister
Bsingleton
Ccontainer.resolve(MyRepository)
Dprovide
Attempts:
3 left
💡 Hint
Common Mistakes
Using provide instead of register
Not resolving dependency inside lambda