Skip to content

Commit b5f9384

Browse files
Optimization of object composition creation
1 parent 42d1ef2 commit b5f9384

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/Pure.DI.Core/Core/Code/RootBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ private void BuildCode(CodeContext parentCtx)
8686
return;
8787
}
8888

89+
if (!string.IsNullOrEmpty(var.LocalFunctionName))
90+
{
91+
parentCtx.Lines.AppendLine($"{var.LocalFunctionName}();");
92+
return;
93+
}
94+
8995
var lines = new LinesBuilder();
9096
var ctx = parentCtx with
9197
{

tests/Pure.DI.UsageTests/UseCases/JsonSerializationScenario.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private void Setup() =>
112112
DI.Setup(nameof(Composition))
113113
.Root<ISettingsService>(nameof(Settings))
114114
.Bind().To<SettingsService>()
115-
.Bind().To(_ => new JsonSerializerOptions { WriteIndented = true })
115+
.Bind().As(Singleton).To(_ => new JsonSerializerOptions { WriteIndented = true })
116116
.Bind(JSON).To<JsonSerializerOptions, Func<string, TT?>>(options => json => JsonSerializer.Deserialize<TT>(json, options))
117117
.Bind(JSON).To<JsonSerializerOptions, Func<TT, string>>(options => value => JsonSerializer.Serialize(value, options))
118118
.Bind().As(Singleton).To<Storage>();

0 commit comments

Comments
 (0)