Skip to content

Commit

Permalink
Refined DataLoader Source Generator (#5689)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Jan 15, 2023
1 parent a50cfed commit a730ed5
Show file tree
Hide file tree
Showing 17 changed files with 501 additions and 92 deletions.
Expand Up @@ -11,14 +11,16 @@ public static class ErrorHelper
public const string Title = "title";
public const string ErrorCategory = "HotChocolateSourceGenerator";

#pragma warning disable RS2008
private static readonly DiagnosticDescriptor _missingDependency =
new DiagnosticDescriptor(
id: ErrorCodes.DependencyMissing,
title: "Dependency Missing",
messageFormat: "The package reference `{0}` is missing.\r\n`dotnet add package {0}`",
messageFormat: "The package reference `{0}` is missing. `dotnet add package {0}`",
category: ErrorCategory,
DiagnosticSeverity.Error,
isEnabledByDefault: true);
#pragma warning restore RS2008

public static void ReportDiagnostic(
this GeneratorExecutionContext context,
Expand Down Expand Up @@ -126,10 +128,10 @@ public static class ErrorHelper
.SetMessage(exception.Message + Environment.NewLine + exception.GetType().Name)
.SetException(exception)
.Build());

public static void ReportMissingDependency(
GeneratorExecutionContext context,
string packageName) =>
context.ReportDiagnostic(_missingDependency, packageName);
}
}
}
Expand Up @@ -20,7 +20,8 @@ public static partial class RequestExecutorBuilderExtensions
where TService : class, IDataLoader
where TImplementation : class, TService
{
builder.Services.TryAddScoped<TService, TImplementation>();
builder.Services.TryAddScoped<TImplementation>();
builder.Services.TryAddScoped<TService>(sp => sp.GetRequiredService<TImplementation>());
return builder;
}

Expand Down

0 comments on commit a730ed5

Please sign in to comment.