如何在没有参考谷物实施的情况下调用奥尔良粮食方法?

时间:2018-06-04 23:11:56

标签: .net .net-core orleans

如果没有粮食实施的参考,如何调用奥尔良粮食方法?

  • Grain客户端 - .Net核心应用程序。
  • Grain实现类 - 经典.Net Framework库,不能添加到.Net Core应用程序。

2 个答案:

答案 0 :(得分:3)

从客户端项目中仅引用接口项目(Core - > Standard)。

从主机项目引用实现项目(Full - > Full)和实现项目引用接口项目(Full - > Standard)。

它就像一个魅力,见:https://github.com/lmagyar/SO_Question_50689964

答案 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);
    }

}

https://github.com/Serj-Tm/Orleans.MinimalSample