dev
This commit is contained in:
parent
c17f94ad73
commit
b0c537fef8
|
|
@ -14,7 +14,7 @@ namespace GameData.UnitTests
|
||||||
[Test]
|
[Test]
|
||||||
public void Test1()
|
public void Test1()
|
||||||
{
|
{
|
||||||
var client = new ExpenseRepository();
|
var client = new ExpenseRepository(null);
|
||||||
var test = client.GetAll();
|
var test = client.GetAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Autofac" Version="7.1.0" />
|
<PackageReference Include="Autofac" Version="7.1.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
using GameModel;
|
using GameModel;
|
||||||
using GameModel.Contract;
|
using GameModel.Contract;
|
||||||
|
using GameModel.Settings;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -10,13 +12,18 @@ namespace GameData.Repository
|
||||||
{
|
{
|
||||||
public class ExpenseRepository : IExpenseRepository
|
public class ExpenseRepository : IExpenseRepository
|
||||||
{
|
{
|
||||||
|
readonly ILogger<ExpenseRepository> _log;
|
||||||
private ApiClient _client;
|
private ApiClient _client;
|
||||||
|
private AppSettings _appSettings;
|
||||||
string Url => "items/expense";
|
string Url => "items/expense";
|
||||||
|
|
||||||
public ExpenseRepository()
|
public ExpenseRepository(ILogger<ExpenseRepository> log, AppSettings appSettings)
|
||||||
{
|
{
|
||||||
|
_appSettings = appSettings;
|
||||||
|
_log = log;
|
||||||
_client = new ApiClient();
|
_client = new ApiClient();
|
||||||
|
|
||||||
|
_log?.LogWarning("TESTWARN");
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Expense> GetAll()
|
public IEnumerable<Expense> GetAll()
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,6 @@ namespace GameModel.Settings
|
||||||
{
|
{
|
||||||
public class AppSettings
|
public class AppSettings
|
||||||
{
|
{
|
||||||
public string Test { get; set; }
|
public string ApiToken { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,15 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AutofacSerilogIntegration" Version="5.0.0" />
|
||||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
<PackageReference Include="Spectre.Console" Version="0.48.0" />
|
<PackageReference Include="Spectre.Console" Version="0.48.0" />
|
||||||
<PackageReference Include="Spectre.Console.Json" Version="0.48.0" />
|
<PackageReference Include="Spectre.Console.Json" Version="0.48.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
// See https://aka.ms/new-console-template for more information
|
// See https://aka.ms/new-console-template for more information
|
||||||
using Autofac;
|
using Autofac;
|
||||||
|
using Autofac.Core;
|
||||||
|
using AutofacSerilogIntegration;
|
||||||
using CommandLine;
|
using CommandLine;
|
||||||
using GameData;
|
using GameData;
|
||||||
using GameData.Repository;
|
using GameData.Repository;
|
||||||
|
|
@ -13,7 +15,8 @@ using GameModel.Settings;
|
||||||
using KoogleCli.Model;
|
using KoogleCli.Model;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
using Spectre.Console.Json;
|
using Spectre.Console.Json;
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
@ -28,9 +31,12 @@ AnsiConsole.MarkupLine("Welcome to [green]koogle[/]");
|
||||||
|
|
||||||
var container = Register();
|
var container = Register();
|
||||||
|
|
||||||
var serviceCollection = new ServiceCollection();
|
//var serviceCollection = new ServiceCollection();
|
||||||
//serviceCollection.AddLogging();
|
//serviceCollection.AddLogging();
|
||||||
|
|
||||||
|
var loggerFactory = container.Resolve<ILoggerFactory>();
|
||||||
|
loggerFactory.AddSerilog();
|
||||||
|
|
||||||
|
|
||||||
var scope = container.BeginLifetimeScope(RootLifetimeTag, b =>
|
var scope = container.BeginLifetimeScope(RootLifetimeTag, b =>
|
||||||
{
|
{
|
||||||
|
|
@ -40,37 +46,18 @@ var scope = container.BeginLifetimeScope(RootLifetimeTag, b =>
|
||||||
|
|
||||||
Autofac.IContainer Register()
|
Autofac.IContainer Register()
|
||||||
{
|
{
|
||||||
|
|
||||||
var configurationBuilder = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
|
||||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
|
||||||
//.AddXmlFile("appsettings.xml", optional: true, reloadOnChange: true)
|
|
||||||
//.AddEnvironmentVariables()
|
|
||||||
//.AddCommandLine(args);
|
|
||||||
;
|
|
||||||
|
|
||||||
// Add your custom configuration provider here if needed
|
|
||||||
// .Add(new CustomConfigurationSource());
|
|
||||||
|
|
||||||
IConfiguration configuration = configurationBuilder.Build();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var someSettings = configuration.GetSection(typeof(AppSettings).Name).Get<AppSettings>();
|
|
||||||
|
|
||||||
|
|
||||||
var builder = new ContainerBuilder();
|
var builder = new ContainerBuilder();
|
||||||
builder.RegisterInstance<AppSettings>(someSettings);
|
|
||||||
|
//builder.Populate(serviceCollection);
|
||||||
|
RegisterAppsettings(builder);
|
||||||
|
|
||||||
|
RegisterLogging(builder);
|
||||||
|
|
||||||
builder.RegisterType<ExpenseRepository>().As<IExpenseRepository>();
|
builder.RegisterType<ExpenseRepository>().As<IExpenseRepository>();
|
||||||
return builder.Build();
|
return builder.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var test = container.Resolve<AppSettings>();
|
|
||||||
Console.WriteLine( test.Test);
|
|
||||||
Console.ReadLine();
|
|
||||||
|
|
||||||
ShowMainMenu();
|
ShowMainMenu();
|
||||||
void ShowMainMenu()
|
void ShowMainMenu()
|
||||||
{
|
{
|
||||||
|
|
@ -135,7 +122,7 @@ void NewGameAction()
|
||||||
|
|
||||||
void StartGameAction(string gameName)
|
void StartGameAction(string gameName)
|
||||||
{
|
{
|
||||||
_gs = new GameService();
|
_gs = new GameService(container);
|
||||||
var bs = _gs.Start(new[] { 1,2,3,4}, GetGameSettings(gameName), gameName );
|
var bs = _gs.Start(new[] { 1,2,3,4}, GetGameSettings(gameName), gameName );
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -336,3 +323,38 @@ static void GetRow(int row, out Text text1, out Text text2, out Text text3, out
|
||||||
//padCol4 = new Padder(text4); //.PadLeft(16).PadBottom(0).PadTop(0);
|
//padCol4 = new Padder(text4); //.PadLeft(16).PadBottom(0).PadTop(0);
|
||||||
//padCol5 = new Padder(text5); //.PadLeft(16).PadBottom(0).PadTop(0);
|
//padCol5 = new Padder(text5); //.PadLeft(16).PadBottom(0).PadTop(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void RegisterAppsettings(ContainerBuilder builder)
|
||||||
|
{
|
||||||
|
var configurationBuilder = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
||||||
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||||
|
//.AddXmlFile("appsettings.xml", optional: true, reloadOnChange: true)
|
||||||
|
//.AddEnvironmentVariables()
|
||||||
|
//.AddCommandLine(args);
|
||||||
|
;
|
||||||
|
|
||||||
|
// Add your custom configuration provider here if needed
|
||||||
|
// .Add(new CustomConfigurationSource());
|
||||||
|
|
||||||
|
IConfiguration configuration = configurationBuilder.Build();
|
||||||
|
var someSettings = configuration.GetSection(typeof(AppSettings).Name).Get<AppSettings>();
|
||||||
|
builder.RegisterInstance(someSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RegisterLogging(ContainerBuilder builder)
|
||||||
|
{
|
||||||
|
string basedir = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
|
|
||||||
|
// create root logger
|
||||||
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.WriteTo.File(basedir + "/Logs/log-.txt", rollingInterval: RollingInterval.Day)
|
||||||
|
.CreateLogger();
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/41414796/how-to-get-microsoft-extensions-loggingt-in-console-application-using-serilog
|
||||||
|
builder.RegisterInstance(new LoggerFactory())
|
||||||
|
.As<ILoggerFactory>();
|
||||||
|
builder.RegisterGeneric(typeof(Logger<>))
|
||||||
|
.As(typeof(ILogger<>))
|
||||||
|
.SingleInstance();
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"AppSettings": {
|
"AppSettings": {
|
||||||
"Test": "value"
|
"ApiToken": "LT9iPa1EuaaRB0h2VL45fVPLLK7Rt0wb"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue