Beispiel #1
0
        public static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder().AddEnvironmentVariables().Build();
            var Port          = int.Parse(configuration.GetValue <string>("PORT") ?? "50051");
            var Host          = configuration.GetValue <string>("HOST") ?? "localhost";
            var MongoPort     = configuration.GetValue <string>("MONGO_PORT") ?? "27017";
            var MongoHost     = configuration.GetValue <string>("MONGO_HOST") ?? "localhost";

            var context           = new Data.Context(MongoPort, MongoHost);
            var productRepository = new ProductRepository(context);
            var userRepository    = new UserRepository(context);

            Server server = new Server
            {
                Services = { Discount.BindService(new DiscountService(productRepository, userRepository)) },
                Ports    = { new ServerPort(Host, Port, ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("Server listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }