Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Consider renaming the methods on IApplicationLifetimeEvents (and maybe the interface) #895

Closed
davidfowl opened this issue Dec 3, 2016 · 7 comments

Comments

@davidfowl
Copy link
Member

Instead of On* which looks like an event, maybe they should be proper method names (verbs).

public interface IApplicationLifetimeEvents
{
   // Maps to ApplicationStarted, this is where you populate caches etc (should it be async even though startup isn't).
   void InitializeApplication();

    // Maps to ApplicationStopping. Gives the application a chance to run logic before requests are drained.
   void StopApplication(); 
}

I can't think of a reason to handle ApplicationStopped. At that point the service provider is already disposed so you can't really call into anything safely.

@NickCraver
Copy link

NickCraver commented Dec 3, 2016

+1 on stripping "On"

However, the OnApplicationStopped call was useful. We planned on using it for telemetry after moving There are many uses in hosting environments for this: telemetry, removal from the load balancer, shared cache notifications, anything with queues and master professing, etc. We even do things like stop logging errors while a shutdown occurs because they're so much racing happening as to be unpredictable.

Please don't remove this call...unless there's another equivalent in the pipe we can hook into here?

@davidfowl
Copy link
Member Author

I'm on putting it back if we can find scenarios where it's usable. The fact that the service provider has already disposed everything is my motivation for removing it. If you call into things that have been disposed, they'll go boom.

@Tratcher
Copy link
Member

Tratcher commented Dec 5, 2016

Design review:
IHostedService

  • ctor
  • Start
  • Stop
  • Dispose (if IDisposable)

davidfowl added a commit that referenced this issue Dec 6, 2016
- Renamed the type to IHostedService and added Start and Stop.
- Split up the IHostedService execution and IApplicationLifetime to avoid
circular references
- Trigger IHostedService.Start after starting the server
- Trigger IHostedService.Stop before disposing the service provider

#895 #894
@benaadams
Copy link
Contributor

benaadams commented Dec 6, 2016

Hmm... Start and Stop sound like commands rather than things happening.

Present participle better: Starting and Stopping if early in pipeline?
Past tense if later Started and Stopped?

@davidfowl
Copy link
Member Author

Thats the point. It's it's more like IRegisteredObject in previous ASP.NET. It's a service that gets notified on Start up of the application (after listening) and after before dispose. It's explicitly not about application events, thats the fundamental change.

@benaadams
Copy link
Contributor

Aha, gotcha. So its the declaration of the Start and Stop methods in the interface. Makes sense then 😄

@davidfowl
Copy link
Member Author

Yep!

davidfowl added a commit that referenced this issue Dec 14, 2016
- Renamed the type to IHostedService and added Start and Stop.
- Split up the IHostedService execution and IApplicationLifetime to avoid
circular references
- Trigger IHostedService.Start after starting the server
- Trigger IHostedService.Stop before disposing the service provider

#895 #894
@davidfowl davidfowl self-assigned this Dec 15, 2016
@davidfowl davidfowl modified the milestones: 1.1.0-preview1, 1.2.0 Dec 15, 2016
@muratg muratg modified the milestones: 1.2.0, 2.0.0 Jan 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants