Skip to content

Commit

Permalink
Fix actor generation template (#2067)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyRokhin authored Oct 19, 2023
1 parent 4582870 commit 55d06bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/Proto.Cluster.CodeGen/Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,17 @@ public async Task ReceiveAsync(global::Proto.IContext context)
=> new global::Proto.Cluster.ClusterKind(Kind, global::Proto.Props.FromProducer(() => new {{Name}}Actor(innerFactory)));
public static global::Proto.Cluster.ClusterKind GetClusterKind<T>(global::System.IServiceProvider serviceProvider, params object[] parameters) where T : {{Name}}Base
=> new global::Proto.Cluster.ClusterKind(Kind, global::Proto.Props.FromProducer(() => new {{Name}}Actor((ctx, id) => global::Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance<T>(serviceProvider, ctx, id, parameters))));
=> new global::Proto.Cluster.ClusterKind(Kind, global::Proto.Props.FromProducer(() => new {{Name}}Actor((ctx, id) =>
{
var allParameters = new object[parameters.Length + 2];
allParameters[0] = ctx;
allParameters[1] = id;
if (parameters.Length > 0)
{
parameters.CopyTo(allParameters, 2);
}
return global::Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance<T>(serviceProvider, allParameters);
})));
}
{{/each}}
}
Expand Down
12 changes: 11 additions & 1 deletion tests/Proto.Cluster.CodeGen.Tests/ExpectedOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,16 @@ public async Task ReceiveAsync(global::Proto.IContext context)
=> new global::Proto.Cluster.ClusterKind(Kind, global::Proto.Props.FromProducer(() => new TestGrainActor(innerFactory)));

public static global::Proto.Cluster.ClusterKind GetClusterKind<T>(global::System.IServiceProvider serviceProvider, params object[] parameters) where T : TestGrainBase
=> new global::Proto.Cluster.ClusterKind(Kind, global::Proto.Props.FromProducer(() => new TestGrainActor((ctx, id) => global::Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance<T>(serviceProvider, ctx, id, parameters))));
=> new global::Proto.Cluster.ClusterKind(Kind, global::Proto.Props.FromProducer(() => new TestGrainActor((ctx, id) =>
{
var allParameters = new object[parameters.Length + 2];
allParameters[0] = ctx;
allParameters[1] = id;
if (parameters.Length > 0)
{
parameters.CopyTo(allParameters, 2);
}
return global::Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance<T>(serviceProvider, allParameters);
})));
}
}
12 changes: 11 additions & 1 deletion tests/Proto.Cluster.CodeGen.Tests/ExpectedOutputPackageless.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,16 @@ public async Task ReceiveAsync(global::Proto.IContext context)
=> new global::Proto.Cluster.ClusterKind(Kind, global::Proto.Props.FromProducer(() => new TestGrainActor(innerFactory)));

public static global::Proto.Cluster.ClusterKind GetClusterKind<T>(global::System.IServiceProvider serviceProvider, params object[] parameters) where T : TestGrainBase
=> new global::Proto.Cluster.ClusterKind(Kind, global::Proto.Props.FromProducer(() => new TestGrainActor((ctx, id) => global::Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance<T>(serviceProvider, ctx, id, parameters))));
=> new global::Proto.Cluster.ClusterKind(Kind, global::Proto.Props.FromProducer(() => new TestGrainActor((ctx, id) =>
{
var allParameters = new object[parameters.Length + 2];
allParameters[0] = ctx;
allParameters[1] = id;
if (parameters.Length > 0)
{
parameters.CopyTo(allParameters, 2);
}
return global::Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance<T>(serviceProvider, allParameters);
})));
}
}

0 comments on commit 55d06bb

Please sign in to comment.