🚧 Core improvements

This commit is contained in:
2020-03-01 22:46:07 +04:00
parent bae09d5ba4
commit a7b3f97f1a
6 changed files with 73 additions and 4 deletions
+10 -2
View File
@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Kruzya.TelegramBot.Core
{
@@ -47,7 +48,7 @@ namespace Kruzya.TelegramBot.Core
// And register in internal temporary array.
var modulesDirectory = new List<string>(new string[]
{
Path.Join(Assembly.GetExecutingAssembly().Location, "modules"),
Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "modules"),
Path.Join(Environment.CurrentDirectory, "modules")
});
@@ -58,7 +59,7 @@ namespace Kruzya.TelegramBot.Core
return modulesDirectory;
}
}
#endregion
public Core(IConfiguration configuration)
@@ -92,6 +93,12 @@ namespace Kruzya.TelegramBot.Core
types.AddRange(assemblyTypes);
}
}
// Instantiate them.
foreach (var module in types)
{
EnsureLoaded(module);
}
}
/// <summary>
@@ -143,6 +150,7 @@ namespace Kruzya.TelegramBot.Core
if (module == null)
{
module = (Module) Activator.CreateInstance(moduleType, this);
Console.WriteLine($"Started module {module.GetType().FullName}");
_modules.Add(module);
}