如果没有粮食实施的参考,如何调用奥尔良粮食方法?
答案 0 :(得分:3)
从客户端项目中仅引用接口项目(Core - > Standard)。
从主机项目引用实现项目(Full - > Full)和实现项目引用接口项目(Full - > Standard)。
答案 1 :(得分:0)
.Net Framework控制台应用程序
Install-Package Microsoft.Orleans.Core.Abstractions
Install-Package Microsoft.Orleans.OrleansCodeGenerator.Build
Install-Package Microsoft.Orleans.Server
class Program
{
static async Task Main(string[] args)
{
await StartSilo();
}
static async Task StartSilo()
{
using (var host = new SiloHostBuilder()
.UseLocalhostClustering()
//.ConfigureLogging(logging => logging.AddConsole())
.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(SampleGrain).Assembly).WithReferences())
.Build())
{
await host.StartAsync();
Console.WriteLine("Silo started. Press any key to terminate...");
Console.ReadKey();
}
}
}
public class SampleGrain : Grain, ISample
{
public Task<string> Ping(string message)
{
Console.WriteLine($"Pinged with '{message}'");
return Task.FromResult($"Message '{message}' received");
}
}
.Net Standard类库
Install-Package Microsoft.Orleans.Core.Abstractions
public interface ISample : IGrainWithStringKey
{
Task<string> Ping(string message);
}
.Net Core控制台应用程序
Install-Package Microsoft.Orleans.OrleansCodeGenerator.Build
Install-Package Microsoft.Orleans.Client
static async Task Main(string[] args)
{
await PingSample();
}
static async Task PingSample()
{
using (var client = new ClientBuilder()
.UseLocalhostClustering()
//.ConfigureLogging(logging => logging.AddConsole())
.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ISample).Assembly).WithReferences())
.Build())
{
await client.Connect();
Console.WriteLine("Client successfully connected to silo host.");
var sample = client.GetGrain<ISample>("one");
var result = await sample.Ping("hello");
Console.WriteLine(result);
}
}