This repository was archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Dispose the host if Initialize fails #1318
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -369,6 +369,23 @@ public void DoNotCaptureStartupErrorsByDefault() | |
| Assert.Equal("A public method named 'ConfigureProduction' or 'Configure' could not be found in the 'Microsoft.AspNetCore.Hosting.Fakes.StartupBoom' type.", exception.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ServiceProviderDisposedOnBuildException() | ||
| { | ||
| var service = new DisposableService(); | ||
| var hostBuilder = new WebHostBuilder() | ||
| .UseServer(new TestServer()) | ||
| .ConfigureServices(services => | ||
| { | ||
| // Added as a factory since instances are never disposed by the container | ||
| services.AddSingleton(sp => service); | ||
| }) | ||
| .UseStartup<StartupWithResolvedDisposableThatThrows>(); | ||
|
|
||
| Assert.Throws<InvalidOperationException>(() => hostBuilder.Build()); | ||
| Assert.True(service.Disposed); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CaptureStartupErrorsHonored() | ||
| { | ||
|
|
@@ -1050,6 +1067,16 @@ public void Configure(IApplicationBuilder app) | |
| } | ||
| } | ||
|
|
||
| public class DisposableService : IDisposable | ||
| { | ||
| public bool Disposed { get; private set; } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| Disposed = true; | ||
| } | ||
| } | ||
|
|
||
| public class TestHostingStartup : IHostingStartup | ||
| { | ||
| public void Configure(IWebHostBuilder builder) | ||
|
|
@@ -1068,6 +1095,24 @@ public void Configure(IWebHostBuilder builder) | |
| } | ||
| } | ||
|
|
||
| public class StartupWithResolvedDisposableThatThrows | ||
| { | ||
| public StartupWithResolvedDisposableThatThrows(DisposableService service) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| public void ConfigureServices(IServiceCollection services) | ||
| { | ||
| throw new InvalidOperationException(); | ||
| } | ||
|
|
||
| public void Configure(IApplicationBuilder app) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: continue the trend where empty methods are shortened as
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's a consistent trend. |
||
| { | ||
|
|
||
| } | ||
| } | ||
|
|
||
| public class TestLoggerProvider : ILoggerProvider | ||
| { | ||
| public TestSink Sink { get; set; } = new TestSink(); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
public void ConfigureServices(IServiceCollection services) => throw new InvalidOperationException()