Convert project to perfusion

This commit is contained in:
Nikolay Kochulin 2018-12-19 15:18:41 +03:00
parent 58be680e4f
commit 1394062930
No known key found for this signature in database
GPG Key ID: 740A804DEB1981AC
6 changed files with 24 additions and 19 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "perfusion"]
path = perfusion
url = http://lserver1/git/perfusion.git

View File

@ -1,9 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Dapper;
using MySql.Data.MySqlClient;
using Perfusion;
namespace JetKarmaBot
{
@ -105,7 +106,7 @@ namespace JetKarmaBot
#endregion
#region service
public Db(Config cfg)
public Db([Inject(true)]Config cfg)
{
Log("Initializing...");
Conn = new MySqlConnection(cfg.ConnectionString);

View File

@ -1,4 +1,5 @@
using JetKarmaBot.Commands;
using Perfusion;
using System;
using System.Collections.Generic;
using System.Linq;
@ -22,9 +23,8 @@ namespace JetKarmaBot
client.SendTextMessageAsync(u.Value.ChatId, message);
}
public JetKarmaBot(Config cfg, Db db)
public JetKarmaBot([Inject(true)]Config cfg)
{
this.db = db;
var httpProxy = new WebProxy($"{cfg.ProxyUrl}:{cfg.ProxyPort}")
{
Credentials = new NetworkCredential(cfg.ProxyLogin, cfg.ProxyPassword)
@ -46,8 +46,9 @@ namespace JetKarmaBot
#endregion
#region service
Db db { get; }
[Inject(true)] Db db { get; set; }
TelegramBotClient client { get; }
[Inject(true)] Container container { get; set; }
User me { get; }
ChatCommandRouter commands;
@ -65,10 +66,10 @@ namespace JetKarmaBot
void InitCommands()
{
commands = new ChatCommandRouter();
commands.Add(new StartCommand(db));
commands.Add(new EchoCommand(client));
commands.Add(new DefineCommand(client));
commands.Add(new AwardCommand(db, client, me));
commands.Add(container.ResolveObject(new StartCommand(db)));
commands.Add(container.ResolveObject(new EchoCommand(client)));
commands.Add(container.ResolveObject(new DefineCommand(client)));
commands.Add(container.ResolveObject(new AwardCommand(db, client, me)));
}
#endregion

View File

@ -10,6 +10,7 @@
<PackageReference Include="MySql.Data" Version="8.0.13" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Telegram.Bot" Version="14.10.0" />
<ProjectReference Include="..\perfusion\Perfusion\Perfusion.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -1,4 +1,5 @@
using System;
using Perfusion;
namespace JetKarmaBot
{
@ -6,23 +7,20 @@ namespace JetKarmaBot
{
public static void Main(string[] args)
{
Current = new App(new Config("karma.cfg.json"));
Container c = new Container();
c.AddInstance(new Config("karma.cfg.json"));
Current = c.GetInstance(typeof(App)) as App;
Current.Run();
Console.ReadKey();
}
public static App Current { get; private set; }
public App(Config cfg)
public void Run()
{
Config = cfg;
Db = new Db(Config);
Watcher = new JetKarmaBot(Config, Db);
Console.WriteLine("JatKarmaBot started!");
}
Config Config { get; }
Db Db { get; }
JetKarmaBot Watcher { get; }
[Inject(true)] JetKarmaBot Watcher { get; }
}
}

1
perfusion Submodule

@ -0,0 +1 @@
Subproject commit a9bd490c796b243245573ca4c9739a29364d2dde