DI中Transient Scoped Singleton Instance的区别

时间:2023-03-08 20:20:54

DI中Transient Scoped Singleton Instance的区别

DI中Transient Scoped Singleton Instance的区别

Observe which of the OperationId values varies within a request, and between requests.

  • Transient objects are always different; a new instance is provided to every controller and every service.
  • Scoped objects are the same within a request, but different across different requests
  • Singleton objects are the same for every object and every request (regardless of whether an instance is provided in ConfigureServices)