示例#1
0
        } // End Task RunAsWindowsService

        static async System.Threading.Tasks.Task RunAsDaemon(string[] args)
        {
            Microsoft.Extensions.Hosting.IHost host =
                new Microsoft.Extensions.Hosting.HostBuilder()
                .ConfigureHostConfiguration(configHost =>
            {
                configHost.SetBasePath(System.IO.Directory.GetCurrentDirectory());
                configHost.AddEnvironmentVariables(prefix: "ASPNETCORE_");
                configHost.AddCommandLine(args);
            })
                .ConfigureAppConfiguration((hostContext, configApp) =>
            {
                configApp.SetBasePath(System.IO.Directory.GetCurrentDirectory());
                configApp.AddEnvironmentVariables(prefix: "ASPNETCORE_");
                configApp.AddJsonFile($"appsettings.json", true);
                configApp.AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", true);
                configApp.AddCommandLine(args);
            })
                .ConfigureServices((hostContext, services) =>
            {
                services.AddLogging();
                services.AddHostedService <LinuxServiceHost>();
                services.AddSingleton(typeof(ICommonService), typeof(CommonSampleService));

                // My configuration
                services.AddSingleton(new MyConfig());
            })
                .ConfigureLogging((hostContext, configLogging) =>
            {
                // configLogging.AddSerilog(new LoggerConfiguration()
                //           .ReadFrom.Configuration(hostContext.Configuration)
                //           .CreateLogger());
                configLogging.AddConsole();
                configLogging.AddDebug();
            })
                .Build();


            // IServiceCollection isc = host.Services.GetRequiredService<IServiceCollection>();
            // IConfiguration confy = host.Services.GetRequiredService<IConfiguration>();


            // host.Services;

            await host.RunAsync();
        } // End Task RunAsDaemon
示例#2
0
        static async Task Main(string[] args)
        {
            Console.WriteLine(Environment.CurrentDirectory);

            var host = new Microsoft.Extensions.Hosting.HostBuilder()
                       .ConfigureServices((context, services) => {
                services.AddLogging();
                services.AddKadderGrpcServer(builder =>
                {
                    builder.Options = new GrpcServerOptions()
                    {
                        Host          = "0.0.0.0",
                        Port          = 13002,
                        NamespaceName = "Atlantis.Simple",
                        ServiceName   = "AtlantisService",
                        // ScanAssemblies = new string[]
                        // {
                        //     typeof(Program).Assembly.FullName
                        // }
                    };
                    Console.WriteLine(builder.Options.ScanAssemblies[0]);
                    builder.AddInterceptor <LoggerInterceptor>();
                });
                services.AddScoped <IPersonMessageServicer, PersonMessageServicer>();
                services.AddScoped <IAnimalMessageServicer, AnimalMessageServicer>();
                services.AddScoped <INumberMessageServicer, NumberMessageServicer>();
                services.AddScoped <ImplServicer>();
                services.AddScoped <AttributeServicer>();
                services.AddScoped <EndwidthKServicer>();

                Console.WriteLine("Server is running...");
            }).Build();

            host.Services.StartKadderGrpc();
            await host.RunAsync();
        }