Skip to content

Commit

Permalink
Merge pull request #203 from atc-net/feature/Fix-ServiceCollectionExt…
Browse files Browse the repository at this point in the history
…ensions-EndpointHandler

Feature/fix service collection extensions endpoint handler
  • Loading branch information
davidkallesen authored Aug 9, 2024
2 parents 9cd5d46 + a83645b commit aa08999
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public string Generate()
sb.AppendLine();
sb.AppendLine(8, "services.AddMemoryCache();");
sb.AppendLine();
sb.AppendLine(8, "services.ConfigureDomainServices(builder.Configuration);");
sb.AppendLine(8, "services.ConfigureDomainHandlers(builder.Configuration);");
sb.AppendLine();
sb.AppendLine(8, "services.AddValidatorsFromAssemblyContaining<IDomainAssemblyMarker>(ServiceLifetime.Singleton);");
sb.AppendLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void GenerateAssemblyMarker()
content);
}

public void GenerateServiceCollectionExtensions()
public void GenerateServiceCollectionEndpointHandlerExtensions()
{
var sbServicesHandlerRegistrations = new StringBuilder();
foreach (var urlPath in openApiDocument.Paths)
Expand All @@ -182,13 +182,16 @@ public void GenerateServiceCollectionExtensions()
}
}

sbServicesHandlerRegistrations.AppendLine();
sbServicesHandlerRegistrations.AppendLine("return services;");

var methodConfigureDomainServices = new MethodParameters(
DocumentationTags: null,
Attributes: null,
AccessModifiers.PublicStatic,
ReturnGenericTypeName: null,
ReturnTypeName: "IServiceCollection",
Name: "ConfigureDomainServices",
Name: "ConfigureDomainHandlers",
Parameters:
[
new(
Expand All @@ -212,32 +215,6 @@ public void GenerateServiceCollectionExtensions()
],
AlwaysBreakDownParameters: true,
UseExpressionBody: false,
Content: """
services.DefineHandlersAndServices();
return services;
""");

var methodDefineHandlersAndServices = new MethodParameters(
DocumentationTags: null,
Attributes: null,
AccessModifiers.PublicStatic,
ReturnGenericTypeName: null,
ReturnTypeName: "void",
Name: "DefineHandlersAndServices",
Parameters:
[
new(
Attributes: null,
GenericTypeName: null,
IsGenericListType: false,
TypeName: "this IServiceCollection",
IsNullableType: false,
IsReferenceType: false,
Name: "services",
DefaultValue: null),
],
AlwaysBreakDownParameters: true,
UseExpressionBody: false,
Content: sbServicesHandlerRegistrations.ToString());

var classParameters = new ClassParameters(
Expand All @@ -246,7 +223,7 @@ public void GenerateServiceCollectionExtensions()
DocumentationTags: null,
Attributes: [codeGeneratorAttribute],
AccessModifiers.PublicStaticClass,
ClassTypeName: "ServiceCollectionExtensions",
ClassTypeName: "ServiceCollectionEndpointHandlerExtensions",
GenericTypeName: null,
InheritedClassTypeName: null,
InheritedGenericClassTypeName: null,
Expand All @@ -256,7 +233,6 @@ public void GenerateServiceCollectionExtensions()
Methods:
[
methodConfigureDomainServices,
methodDefineHandlersAndServices,
],
GenerateToStringMethod: false);

Expand All @@ -269,7 +245,7 @@ public void GenerateServiceCollectionExtensions()
var contentWriter = new ContentWriter(logger);
contentWriter.Write(
projectPath,
projectPath.CombineFileInfo("Extensions", "ServiceCollectionExtensions.cs"),
projectPath.CombineFileInfo("Extensions", "ServiceCollectionEndpointHandlerExtensions.cs"),
ContentWriterArea.Src,
content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public void GenerateAssemblyMarker()
content);
}

public void GenerateServiceCollectionExtensions()
=> throw new NotSupportedException($"{nameof(GenerateServiceCollectionExtensions)} is not supported for MVC");
public void GenerateServiceCollectionEndpointHandlerExtensions()
=> throw new NotSupportedException($"{nameof(GenerateServiceCollectionEndpointHandlerExtensions)} is not supported for MVC");

public void MaintainGlobalUsings(
bool removeNamespaceGroupSeparatorInGlobalUsings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IServerDomainGenerator

void GenerateAssemblyMarker();

void GenerateServiceCollectionExtensions();
void GenerateServiceCollectionEndpointHandlerExtensions();

void MaintainGlobalUsings(
bool removeNamespaceGroupSeparatorInGlobalUsings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ document.addEventListener('DOMContentLoaded', function () {
if (svgElement) {
svgElement.remove()
}
}, 10);
}, 100);
}, false);
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<bool> Generate()
serverDomainGeneratorMinimalApi.ScaffoldHandlers();

serverDomainGeneratorMinimalApi.GenerateAssemblyMarker();
serverDomainGeneratorMinimalApi.GenerateServiceCollectionExtensions();
serverDomainGeneratorMinimalApi.GenerateServiceCollectionEndpointHandlerExtensions();

serverDomainGeneratorMinimalApi.MaintainGlobalUsings(
projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings);
Expand Down

0 comments on commit aa08999

Please sign in to comment.