I am trying to understand the meaning of "Scoped objects" and "Transient objects". I was asked in the interview about the usage of this and I said :
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. I gave an example If I have a dashboard with 3-4 widgets and each of these 4 widgets is calling an action method of DashboardController by injecting IDashboardService in the controller. If the IDashboardService is registered as Scoped then only 1 instance is going to be created for "Action1 Widget" which will be used in another subsequent request in "Action2 Widget", "Action3 Widget" and "Action 4 Widget" without creating a new instance.
Now I am not sure if the above sentence is right or wrong but the interviewer asked me how does the .Net core framework know it has to use the same instance as the HTTP request
is stateless.
So can anyone please explain how this works and how the browser and server know if its the same session and how the browser informs to the .net framework that its the same
session so use the same instance in case of Scoped and new for Transient?