Beruflich Dokumente
Kultur Dokumente
Inversion of control
Dependency inversion principal
Benefits:
Promotes loose coupling of components.
Promotes logical abstraction of components.
Improve unit testing
Cleaner and more readable code.
Services are registered at startup and resolve from the container at run time.
The container is responsible of creating and disposing of instances of required services on
demand
Service Lifetime:
o Transient Services:
o Not required to be thread safe
o Potentially less efficient
o Easiest to reason about
o SingleTon Services:
o Generally more performant
o Must be thread-safe
o Suited to functional stateless service. Like function accept input and return output
and no shared state is used.
o Scoped Services:
o Create scoped services per request e.g dbContext
o
Scope Validation
o It is introduced in Core 2.0.
o Enables by default for development
o Validate container scopes at startup
Service Descriptors:
It contain information about registered services.
Multiple Registration:
In multiple registration case for the same contract. It’s the last registration always wins. Consider using
TryAdd method.
Action Injection:
Only work when action specifies the dependency invoked to handle the request.
Middleware Injection:
Scrutor:
It’s a 3rd party library which full fills two gaps that Microsoft lacks
o Scanning Assemblies
o Using the decorator pattern