silo 主机 配置

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Orleans;
using Orleans.Configuration;
using Orleans.Hosting;
using System;
using System.Net;
using System.Threading.Tasks;
using w23082019.Default;

namespace w23082019.Silo {
    class Program {
        static async Task<int> Main(string[] args) {
            try {
                var host = new HostBuilder()
                    .UseOrleans((siloBuilder) => {
                        siloBuilder
                            .UseLocalhostClustering()
                            .Configure(options => {
                                options.ClusterId = "dev";
                                options.ServiceId = "HelloWorldApp";
                            })
                            .Configure(options => options.AdvertisedIPAddress = IPAddress.Loopback)
                            .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(HelloOrleans).Assembly).WithReferences());
                    })
                    .ConfigureLogging(logging => logging.AddConsole())
                    .Build();
                await host.RunAsync();

                return 0;
            } catch (Exception ex) {
                Console.WriteLine(ex);
                return 1;
            }
        }
    }
}

 注意红标 扩展方法要用 有时智能提示不会补全

using Fone.Orleans.Server;
using jingjinxiuchi;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
using w05082019.Default;
using w05082019.Default.AuthGrains;

namespace w05082019.Silo {
    class Program {
        static async Task Main(string[] args) {
            var host=OrleansServer.GetSiloHost(
            //typeof(jingjinxiuchi.Report_Sex),
            //typeof(w05082019.Default.AuthGrains.AuthBasic)
            )
                .ConfigureAppConfiguration((env, config) => {
                    //显示设置当前程序运行目录
                    config.SetBasePath(env.HostingEnvironment.ContentRootPath);
                    System.Console.WriteLine(env.HostingEnvironment.ContentRootPath);
                    //设置内存中的 .NET 对象
                    //config.AddInMemoryCollection(arrayDict);
                    //设置文件, optional选择项为false时 必需存在该文件
                    config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false);
                    //EF以后在讲 自定义提供程序
                    // config.AddEFConfiguration(options => options.UseInMemoryDatabase("InMemoryDb"));
                    //最后设置命令行参数
                    config.AddCommandLine(args);
                })
                .ConfigureServices(svc => {
                    svc.AddDbContext();
                    svc.AddDbContext();
                }).Build();
            await host.RunAsync();
        }
    }
}

这是外部配置的情况,注意 主机异步启动的方式

转载于:https://www.cnblogs.com/ProjectDD/p/11397770.html

你可能感兴趣的:(json)