Skip to content

Commit

Permalink
Fix a bug in which the service lifetime for non-wasm scenarios was in…
Browse files Browse the repository at this point in the history
…correct.
  • Loading branch information
IEvangelist committed Apr 18, 2022
1 parent 74126af commit 214f1e9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Blazor.SourceGenerators/CSharp/CSharpTopLevelObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ internal string ToImplementationString(
builder.AppendTripleSlashInheritdocComments(builder.InterfaceName, details.CSharpPropertyName)
.AppendRaw($"{details.ReturnType} {builder.InterfaceName}.{details.CSharpPropertyName} =>", postIncreaseIndentation: true)
.AppendRaw($"_javaScript.Invoke{details.Suffix}{details.GenericTypeArgs}(", postIncreaseIndentation: true)
.AppendRaw($"\"eval\", \"{details.FullyQualifiedJavaScriptIdentifier}\");");
.AppendRaw($"\"eval\", \"{details.FullyQualifiedJavaScriptIdentifier}\");");

if (!index.IsLast)
{
Expand All @@ -508,6 +508,10 @@ internal string ToServiceCollectionExtensions(

var @interface = options.Implementation.ToInterfaceName();
var nonService = options.Implementation.ToImplementationName(false);
var serviceLifetime = options.IsWebAssembly
? "Singleton"
: "Scoped";

var extensions = $@"// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License:
// https://github.com/IEvangelist/blazorators/blob/main/LICENSE
Expand All @@ -525,7 +529,7 @@ public static class {nonService}ServiceCollectionExtensions
/// </summary>
public static IServiceCollection Add{nonService}Services(
this IServiceCollection services) =>
{addExpression}.AddSingleton<{@interface}, {implementation}>();
{addExpression}.Add{serviceLifetime}<{@interface}, {implementation}>();
}}
";

Expand Down

0 comments on commit 214f1e9

Please sign in to comment.