generated from atkntuncer/console-template-for-dotnetcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
38 lines (33 loc) · 1.45 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using CoreConsoleTemplate.Bussines;
using CoreConsoleTemplate.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using System;
using System.IO;
using System.Threading.Tasks;
namespace CoreConsoleTemplate
{
class Program
{
static void Main(string[] args)
{
var builder = new ConfigurationBuilder();
BuildConfig(builder);
Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(builder.Build()).CreateLogger();
var host = Host.CreateDefaultBuilder().ConfigureServices((context, services) =>
{
services.AddScoped<IDataAccess, DataAccess>();
services.AddSingleton<ISendRequest, SendRequest>();
services.Configure<Configuration>(context.Configuration.GetSection("BotSetttings"));
}).UseSerilog().Build();
var _main = ActivatorUtilities.CreateInstance<Main>(host.Services);
_main.Run().Wait();
}
static void BuildConfig(IConfigurationBuilder builder)
{
builder.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: false, reloadOnChange: true).AddJsonFile($"apsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true, reloadOnChange: true).AddEnvironmentVariables();
}
}
}