Dependecy Injection Example
Project structure
- 01.FrontEnd
- UI + API
- 02.Business
- Bridge to Services - good to call multiple services and return a single object.
- 04.Data
- Service / Provider (Database or external service)
- Service / Provider (Database or external service)
DI (Dependecy Injection)
- Everything is defined on the entrypoint project (Quid.DP.WebApi).
- Can be reusable where needed
- Types of DI:
- Singleton: It creates the instance for the first time and reuses the same object in the all calls.
- Scoped: It is equivalent to a singleton in the current scope. For example, in MVC it creates one instance for each HTTP request, but it uses the same instance in the other calls within the same web request.
- Transient: Lifetime services are created each time they are requested. This lifetime works best for lightweight, stateless services.
UML diagram
Workflow:
(UML Source: https://github.com/mermaid-js/mermaid-live-editor)