-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for other dependency injection containers (e.g. Autofac)
- Added support for other dependency injection containers (e.g. Autofac) when only `Microsoft.Extensions.DependencyInjection.Abstractions` package (version >= 2.1.1) is added to the project. You can set your custom service provider with the extension method `Cli.Ext.SetServiceProvider`. In previous version, this method already existed but accepted a `ServiceProvider` parameter, instead of `IServiceProvider` parameter which allows 3rd party implementations other than the default one in `Microsoft.Extensions.DependencyInjection`. - Reduced minimum version requirement for `Microsoft.Extensions.DependencyInjection` from `6.0.0` to `2.1.1` so that you don't need to update it in legacy projects. Added `Cli.Ext.GetServiceCollection` and `Cli.Ext.GetServiceProviderOrDefault` extension methods.
- Loading branch information
Showing
206 changed files
with
689 additions
and
492 deletions.
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
50 changes: 50 additions & 0 deletions
50
src/DotMake.CommandLine.SourceGeneration.Embedded/CliServiceCollectionExtensions.cs
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
|
||
namespace DotMake.CommandLine | ||
{ | ||
/// <summary> | ||
/// Provides <see cref="IServiceCollection"/> related extension methods for <see cref="Cli"/> services feature. | ||
/// <para> | ||
/// Requires dependency <c>Microsoft.Extensions.DependencyInjection (>= 2.1.1)</c>. | ||
/// <br/>Default implementation <see cref="ServiceCollection"/> is in <c>Microsoft.Extensions.DependencyInjection</c> assembly. | ||
/// </para> | ||
/// </summary> | ||
public static class CliServiceCollectionExtensions | ||
{ | ||
private static readonly IServiceCollection ServiceCollection = new ServiceCollection(); | ||
private static IServiceProvider serviceProvider; | ||
|
||
/// <summary> | ||
/// Registers services into the <see cref="Cli"/>'s default service collection. | ||
/// </summary> | ||
/// <param name="ext">The CliExtensions instance to extend.</param> | ||
/// <param name="configure">An <see cref="Action{IServiceCollection}"/> to configure the <see cref="Cli"/>'s default service collection.</param> | ||
public static void ConfigureServices(this CliExtensions ext, Action<IServiceCollection> configure) | ||
{ | ||
configure(ServiceCollection); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="Cli"/>'s default service collection. | ||
/// </summary> | ||
/// <param name="ext">The CliExtensions instance to extend.</param> | ||
/// <returns>A <see cref="IServiceCollection"/> instance.</returns> | ||
public static IServiceCollection GetServiceCollection(this CliExtensions ext) | ||
{ | ||
return ServiceCollection; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the service provider built from <see cref="Cli"/>'s default service collection (built on first access). | ||
/// If <see cref="CliServiceProviderExtensions.SetServiceProvider"/> was used, then gets the custom <see cref="IServiceProvider"/> that was set. | ||
/// </summary> | ||
/// <param name="ext">The CliExtensions instance to extend.</param> | ||
/// <returns>A <see cref="IServiceProvider"/> instance.</returns> | ||
public static IServiceProvider GetServiceProviderOrDefault(this CliExtensions ext) | ||
{ | ||
return serviceProvider ??= CliServiceProviderExtensions.GetServiceProvider(null) | ||
?? ServiceCollection.BuildServiceProvider(); | ||
} | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
src/DotMake.CommandLine.SourceGeneration.Embedded/CliServiceExtensions.cs
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/DotMake.CommandLine.SourceGeneration.Embedded/CliServiceProviderExtensions.cs
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace DotMake.CommandLine | ||
{ | ||
/// <summary> | ||
/// Provides <see cref="IServiceProvider"/> related extension methods for <see cref="Cli"/> services feature. | ||
/// <para> | ||
/// Requires dependency <c>Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.1.1)</c>. | ||
/// <br/>Although <see cref="IServiceProvider"/> is in <c>System.ComponentModel</c> assembly, | ||
/// used class <see cref="ActivatorUtilities"/> is in <c>Microsoft.Extensions.DependencyInjection.Abstractions</c> assembly. | ||
/// </para> | ||
/// </summary> | ||
public static class CliServiceProviderExtensions | ||
{ | ||
private static IServiceProvider serviceProvider; | ||
|
||
/// <summary> | ||
/// Gets the custom service provider. | ||
/// If <see cref="SetServiceProvider"/> was used, then gets the custom <see cref="IServiceProvider"/> that was set. | ||
/// </summary> | ||
/// <param name="ext">The CliExtensions instance to extend.</param> | ||
/// <returns>A <see cref="IServiceProvider"/> instance or <see langword="null"/>.</returns> | ||
public static IServiceProvider GetServiceProvider(this CliExtensions ext) | ||
{ | ||
return serviceProvider; | ||
} | ||
|
||
/// <summary> | ||
/// Sets a custom service provider built from a custom service collection (to override the internal default one). | ||
/// When <see cref="GetServiceProvider"/> is called, this custom <see cref="IServiceProvider"/> will be returned. | ||
/// </summary> | ||
/// <param name="ext">The CliExtensions instance to extend.</param> | ||
/// <param name="customServiceProvider">The custom <see cref="IServiceProvider"/> instance to use.</param> | ||
public static void SetServiceProvider(this CliExtensions ext, IServiceProvider customServiceProvider) | ||
{ | ||
serviceProvider = customServiceProvider; | ||
} | ||
} | ||
} |
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
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
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
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
4 changes: 2 additions & 2 deletions
4
...otMake.CommandLine.SourceGeneration.CliCommandGenerator/(ModuleInitializerAttribute).g.cs
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
Oops, something went wrong.