diff --git a/sample/TestWebApiGenerator/ServiceRegistrationExtensions.cs b/sample/TestWebApiGenerator/ServiceRegistrationExtensions.cs index f85d5f5..426d352 100644 --- a/sample/TestWebApiGenerator/ServiceRegistrationExtensions.cs +++ b/sample/TestWebApiGenerator/ServiceRegistrationExtensions.cs @@ -5,7 +5,7 @@ namespace TestWebApiGenerator; internal static partial class ServiceRegistrationExtensions { - [GenerateServiceRegistration("Services", ExcludedSections = new[] { "Hsts" }, ImplicitSuffixes = new[] { "Instrumentation", "Exporter" })] + [GenerateConfiguration("Services", ExcludedSections = new[] { "Hsts" }, ImplicitSuffixes = new[] { "Instrumentation", "Exporter" })] public static partial void AddServicesFromConfiguration(this WebApplicationBuilder builder); // [GenerateServiceRegistration("Services")] diff --git a/src/ConfigurationProcessor.Generator/GenerateServiceRegistrationAttribute.cs b/src/ConfigurationProcessor.Generator/GenerateConfigurationAttribute.cs similarity index 82% rename from src/ConfigurationProcessor.Generator/GenerateServiceRegistrationAttribute.cs rename to src/ConfigurationProcessor.Generator/GenerateConfigurationAttribute.cs index dcba033..52752fd 100644 --- a/src/ConfigurationProcessor.Generator/GenerateServiceRegistrationAttribute.cs +++ b/src/ConfigurationProcessor.Generator/GenerateConfigurationAttribute.cs @@ -4,7 +4,7 @@ /// Attribute for generating service registration. /// [AttributeUsage(AttributeTargets.Method)] -public class GenerateServiceRegistrationAttribute : Attribute +public class GenerateConfigurationAttribute : Attribute { /// /// The default configuration file name. @@ -12,9 +12,9 @@ public class GenerateServiceRegistrationAttribute : Attribute public const string DefaultConfigurationFile = "appsettings.json"; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public GenerateServiceRegistrationAttribute(string configurationSection) + public GenerateConfigurationAttribute(string configurationSection) { ConfigurationSection = configurationSection; } diff --git a/src/ConfigurationProcessor.Generator/README.md b/src/ConfigurationProcessor.Generator/README.md index 785e5c0..027713e 100644 --- a/src/ConfigurationProcessor.Generator/README.md +++ b/src/ConfigurationProcessor.Generator/README.md @@ -1,6 +1,6 @@ -# ConfigurationProcessor.DependencyInjection.Generator +# ConfigurationProcessor.Generator -[![NuGet](https://img.shields.io/nuget/v/ConfigurationProcessor.DependencyInjection.Generator.svg?label=ConfigurationProcessor.DependencyInjection.Generator)](https://www.nuget.org/packages/ConfigurationProcessor.DependencyInjection.Generator) +[![NuGet](https://img.shields.io/nuget/v/ConfigurationProcessor.Generator.svg?label=ConfigurationProcessor.Generator)](https://www.nuget.org/packages/ConfigurationProcessor.Generator) This packages uses source generation to generate dependency injection registration methods based on the `appsettings.config` configuration. This is still in beta and the current version partially supports the configuration mechanisms available in the [ConfigurationProcessor.DependencyInjection](https://www.nuget.org/packages/ConfigurationProcessor.DependencyInjection/) package. @@ -11,18 +11,18 @@ This packages uses source generation to generate dependency injection registrati ```csharp internal static partial class ServiceRegistrations { - [GenerateServiceRegistration("Services")] + [GenerateConfiguration("Services")] internal static partial void RegisterServices(this IServiceCollection services, IConfiguration configuration); - [GenerateServiceRegistration("Services")] + [GenerateConfiguration("Services")] public static partial void AddServicesFromConfiguration(this WebApplicationBuilder builder); } ``` -Create a static partial method in a partial class decorated with `GenerateServiceRegistrationAttribute` and that contains an `IServiceCollection` and `IConfiguration` parameters or a single parameter with a parameter type that contains a single `IServiceCollection` and `IConfiguration` property. +Create a static partial method in a partial class decorated with `GenerateConfigurationAttribute` and that contains an `IServiceCollection` and `IConfiguration` parameters or a single parameter with a parameter type that contains a single `IServiceCollection` and `IConfiguration` property. -The `GenerateServiceRegistrationAttribute` requires a single argument , `configurationSection` which will be the configuration section in the `appsettings.json` to read from. +The `GenerateConfigurationAttribute` requires a single argument , `configurationSection` which will be the configuration section in the `appsettings.json` to read from. ### Sample configuration diff --git a/src/ConfigurationProcessor.SourceGeneration/Generator.cs b/src/ConfigurationProcessor.SourceGeneration/Generator.cs index 8282aa4..837039f 100644 --- a/src/ConfigurationProcessor.SourceGeneration/Generator.cs +++ b/src/ConfigurationProcessor.SourceGeneration/Generator.cs @@ -93,7 +93,7 @@ private static bool IsSyntaxTargetForGeneration(SyntaxNode node) => INamedTypeSymbol attributeContainingTypeSymbol = attributeSymbol.ContainingType; string fullName = attributeContainingTypeSymbol.ToDisplayString(); - if (fullName == Parser.GenerateServiceRegistrationAttribute) + if (fullName == Parser.GenerateConfigurationAttributeName) { return methodDeclarationSyntax.Parent as ClassDeclarationSyntax; } diff --git a/src/ConfigurationProcessor.SourceGeneration/Parser.cs b/src/ConfigurationProcessor.SourceGeneration/Parser.cs index 7792b21..dc12fb4 100644 --- a/src/ConfigurationProcessor.SourceGeneration/Parser.cs +++ b/src/ConfigurationProcessor.SourceGeneration/Parser.cs @@ -12,7 +12,7 @@ namespace ConfigurationProcessor.SourceGeneration; internal class Parser { internal const string DefaultConfigurationFile = "appsettings.json"; - internal const string GenerateServiceRegistrationAttribute = "ConfigurationProcessor.GenerateServiceRegistrationAttribute"; + internal const string GenerateConfigurationAttributeName = "ConfigurationProcessor.GenerateConfigurationAttribute"; internal const string ServiceCollectionTypeName = "Microsoft.Extensions.DependencyInjection.IServiceCollection"; internal const string WebApplicationBuilderTypeName = "Microsoft.AspNetCore.Builder.WebApplicationBuilder"; private readonly GeneratorExecutionContext context; @@ -28,7 +28,7 @@ public Parser(GeneratorExecutionContext context, Action reportDiagno internal IReadOnlyList GetServiceRegistrationClasses(IEnumerable classes) { - INamedTypeSymbol? generateServiceRegistrationAttribute = context.Compilation.GetBestTypeByMetadataName(GenerateServiceRegistrationAttribute); + INamedTypeSymbol? generateServiceRegistrationAttribute = context.Compilation.GetBestTypeByMetadataName(GenerateConfigurationAttributeName); if (generateServiceRegistrationAttribute == null) { // nothing to do if this type isn't available diff --git a/src/Directory.Build.props b/src/Directory.Build.props index b46d10b..d4c7778 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -10,7 +10,7 @@ - 0.3.0 + 0.4.0 $(Version)-beta.1