cloudnet-compose/worker/dotnet/Worker/Program.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2018-09-21 20:23:31 +02:00
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using Worker.Data;
using Worker.Entities;
using Worker.Messaging;
using Worker.Workers;
namespace Worker
{
class Program
{
static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
var loggerFactory = new LoggerFactory()
.AddConsole();
var services = new ServiceCollection()
.AddSingleton(loggerFactory)
.AddLogging()
.AddSingleton<IConfiguration>(config)
.AddTransient<IVoteData, MySqlVoteData>()
.AddTransient<IMessageQueue, MessageQueue>()
.AddSingleton<QueueWorker>()
.AddDbContext<VoteContext>(builder => builder.UseMySQL(config["VoteData:ConnectionString"]));
var provider = services.BuildServiceProvider();
var worker = provider.GetService<QueueWorker>();
worker.Start();
}
}
}