Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix actor generation template #2067

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
})));
}
}
Loading