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

Consider removing the dependency between IApplicationLifetime and IApplicationLifetimeEvents #894

Closed
davidfowl opened this issue Dec 3, 2016 · 0 comments
Assignees

Comments

@davidfowl
Copy link
Member

davidfowl commented Dec 3, 2016

The following class will cause a circular dependency error in the DI system:

public class LifetimeEvents : IApplicationLifetimeEvents
{
    public LifetimeEvents(IApplicationLifetime lifetime)
    {

    }

    public void OnApplicationStarted()
    {
        
    }

    public void OnApplicationStopping()
    {
        
    }

    public void OnApplicationStopped()
    {

    }
}

This is because internally, the default implementation of IApplicationLifetime takes an IEnumerable<IApplicationLifetimeEvents>. The reason you might want to inject IApplicationLifetime is because you might want to call StopApplication at some point. Either way, the error is impossible to figure out without understanding how it's implemented.

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
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 added the bug label Dec 15, 2016
@davidfowl davidfowl added this to the 1.2.0 milestone 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

2 participants