This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 310
Allow overriding the hosting service provider #1325
Merged
+103
−4
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b1ad979
Allow external service providers (#550 and #1309)
ENikS da37dab
Consolidated it a bit more
ENikS fc23c07
Removed test
ENikS 207af1d
Spelling
ENikS 8190d24
Update WebHostBuilder.cs
ENikS 75a5b5b
Update TestServerTests.cs
ENikS a83e93e
Update WebHostBuilder.cs
ENikS 4526219
Update WebHostBuilder.cs
ENikS bb4ffe9
Assert creation and disposal service providers
davidfowl 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 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 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 |
---|---|---|
|
@@ -153,7 +153,7 @@ public IWebHost Build() | |
|
||
var hostingServices = BuildCommonServices(out var hostingStartupErrors); | ||
var applicationServices = hostingServices.Clone(); | ||
var hostingServiceProvider = hostingServices.BuildServiceProvider(); | ||
var hostingServiceProvider = GetProviderFromFactory(hostingServices); | ||
|
||
if (!_options.SuppressStatusMessages) | ||
{ | ||
|
@@ -202,6 +202,22 @@ public IWebHost Build() | |
host.Dispose(); | ||
throw; | ||
} | ||
|
||
IServiceProvider GetProviderFromFactory(IServiceCollection collection) | ||
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. Only used once and not complex, inline. 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 think it should remain a method. It's not like it's 2 lines of code. It's a few. |
||
{ | ||
var provider = collection.BuildServiceProvider(); | ||
var factory = provider.GetService<IServiceProviderFactory<IServiceCollection>>(); | ||
|
||
if (factory != null) | ||
{ | ||
using (provider) | ||
{ | ||
return factory.CreateServiceProvider(factory.CreateBuilder(collection)); | ||
} | ||
} | ||
|
||
return provider; | ||
} | ||
} | ||
|
||
private IServiceCollection BuildCommonServices(out AggregateException hostingStartupErrors) | ||
|
This file contains 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
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.
Is it guaranteed that factory exists? What if
serviceProviderFactory
is null?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.
This has been the case since 2.0. There’s always one registered. Unless somebody removes it.
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.
shrug it's a weird use of embedded methods.