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")
|
2018-09-26 13:12:48 +02:00
|
|
|
|
.AddEnvironmentVariables()
|
2018-09-21 20:23:31 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var loggerFactory = new LoggerFactory()
|
|
|
|
|
.AddConsole();
|
|
|
|
|
|
|
|
|
|
var services = new ServiceCollection()
|
|
|
|
|
.AddSingleton(loggerFactory)
|
|
|
|
|
.AddLogging()
|
|
|
|
|
.AddSingleton<IConfiguration>(config)
|
|
|
|
|
.AddTransient<IVoteData, MySqlVoteData>()
|
|
|
|
|
.AddTransient<IMessageQueue, MessageQueue>()
|
|
|
|
|
.AddSingleton<QueueWorker>()
|
2018-09-26 12:32:50 +02:00
|
|
|
|
.AddDbContext<VoteContext>(builder => builder.UseMySQL(config.GetConnectionString("VoteData")));
|
2018-09-21 20:23:31 +02:00
|
|
|
|
|
|
|
|
|
var provider = services.BuildServiceProvider();
|
|
|
|
|
var worker = provider.GetService<QueueWorker>();
|
|
|
|
|
worker.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|