-
Notifications
You must be signed in to change notification settings - Fork 6k
Added details about IEnumerable<T> into DI. #21257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| snippets/configuration/dependency-injection/Program.cs: ~/docs/core/extensions/dependency-injection.md | ||
| snippets/configuration/console-di-ienumerable/Program.cs: ~/docs/core/extensions/dependency-injection.md | ||
| snippets/configuration/console-di-ienumerable/ExampleService.cs: ~/docs/core/extensions/dependency-injection.md | ||
| snippets/configuration/console-json/Program.cs: ~/docs/core/extensions/configuration-providers.md | ||
| snippets/configuration/console-xml/Program.cs: ~/docs/core/extensions/configuration-providers.md | ||
| snippets/configuration/console-ini/Program.cs: ~/docs/core/extensions/configuration-providers.md | ||
| snippets/configuration/console/Program.cs: ~/docs/core/extensions/configuration.md | ||
| snippets/logging/console-formatter-simple/Program.cs: ~/docs/core/extensions/custom-log-formatter.md | ||
| snippets/configuration/custom-provider/Program.cs: ~/docs/core/extensions/custom-configuration-provider.md | ||
| snippets/configuration/console-custom-logging/ColorConsoleLogger.cs: ~/docs/core/extensions/custom-logging-provider.md | ||
| snippets/configuration/console-di-disposable/Program.cs: ~/docs/core/extensions/dependency-injection-guidelines.md | ||
| snippets/configuration/console-di/Program.cs: ~/docs/core/extensions/dependency-injection-usage.md | ||
| snippets/configuration/console-host/Program.cs: ~/docs/core/extensions/generic-host.md | ||
| snippets/configuration/app-lifetime/Program.cs: ~/docs/core/extensions/generic-host.md | ||
| snippets/configuration/app-lifetime/ExampleHostedService.cs: ~/docs/core/extensions/generic-host.md | ||
| snippets/configuration/worker-service-options/Worker.cs: ~/docs/core/extensions/high-performance-logging.md | ||
| snippets/configuration/console/Program.cs: ~/docs/core/extensions/logging-providers.md | ||
| snippets/configuration/worker-service/appsettings.IncludeScopes.json: ~/docs/core/extensions/logging.md | ||
| snippets/configuration/worker-service/Worker.cs: ~/docs/core/extensions/logging.md | ||
| snippets/configuration/console-json/appsettings.json: ~/docs/core/extensions/options.md | ||
| snippets/configuration/console-json/TransientFaultHandlingOptions.cs: ~/docs/core/extensions/options.md | ||
| snippets/configuration/console-json/Program.cs: ~/docs/core/extensions/options.md |
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
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
11 changes: 11 additions & 0 deletions
11
docs/core/extensions/snippets/configuration/console-di-ienumerable/ConsoleMessageWriter.cs
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| using System; | ||
|
|
||
| namespace ConsoleDI.IEnumerableExample | ||
| { | ||
| public class ConsoleMessageWriter : IMessageWriter | ||
| { | ||
| public void Write(string message) => | ||
| Console.WriteLine( | ||
| $"ConsoleMessageWriter.Write(message: \"{message}\")"); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
docs/core/extensions/snippets/configuration/console-di-ienumerable/ExampleService.cs
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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Linq; | ||
|
|
||
| namespace ConsoleDI.IEnumerableExample | ||
| { | ||
| public class ExampleService | ||
| { | ||
| public ExampleService( | ||
| IMessageWriter messageWriter, | ||
| IEnumerable<IMessageWriter> messageWriters) | ||
| { | ||
| Trace.Assert(messageWriter is LoggingMessageWriter); | ||
|
|
||
| var dependencyArray = messageWriters.ToArray(); | ||
| Trace.Assert(dependencyArray[0] is ConsoleMessageWriter); | ||
| Trace.Assert(dependencyArray[1] is LoggingMessageWriter); | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
docs/core/extensions/snippets/configuration/console-di-ienumerable/IMessageWriter.cs
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace ConsoleDI.IEnumerableExample | ||
| { | ||
| public interface IMessageWriter | ||
| { | ||
| void Write(string message); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
docs/core/extensions/snippets/configuration/console-di-ienumerable/LoggingMessageWriter.cs
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace ConsoleDI.IEnumerableExample | ||
| { | ||
| public class LoggingMessageWriter : IMessageWriter | ||
| { | ||
| private readonly ILogger<LoggingMessageWriter> _logger; | ||
|
|
||
| public LoggingMessageWriter(ILogger<LoggingMessageWriter> logger) => | ||
| _logger = logger; | ||
|
|
||
| public void Write(string message) => | ||
| _logger.LogInformation(message); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
docs/core/extensions/snippets/configuration/console-di-ienumerable/Program.cs
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using System.Threading.Tasks; | ||
| using ConsoleDI.IEnumerableExample; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
|
|
||
| namespace ConsoleDI.Example | ||
| { | ||
| class Program | ||
| { | ||
| static Task Main(string[] args) | ||
| { | ||
| IHost host = CreateHostBuilder(args).Build(); | ||
|
|
||
| _ = host.Services.GetService<ExampleService>(); | ||
|
|
||
| return host.RunAsync(); | ||
| } | ||
|
|
||
| static IHostBuilder CreateHostBuilder(string[] args) => | ||
| Host.CreateDefaultBuilder(args) | ||
| .ConfigureServices((_, services) => | ||
| services.AddSingleton<IMessageWriter, ConsoleMessageWriter>() | ||
| .AddSingleton<IMessageWriter, LoggingMessageWriter>() | ||
| .AddSingleton<ExampleService>()); | ||
| } | ||
| } | ||
13 changes: 13 additions & 0 deletions
13
...re/extensions/snippets/configuration/console-di-ienumerable/console-di-ienumerable.csproj
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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net5.0</TargetFramework> | ||
| <RootNamespace>ConsoleDI.IEnumerableExample</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0-rc.2.20475.5" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
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
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
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.