mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
Split Core modules into separate files
This commit is contained in:
parent
a328867e76
commit
dee25fcc23
4 changed files with 81 additions and 68 deletions
28
PluralKit.Core/Modules/ConfigModule.cs
Normal file
28
PluralKit.Core/Modules/ConfigModule.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Autofac;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public class ConfigModule<T>: Module where T: new()
|
||||
{
|
||||
private readonly string _submodule;
|
||||
|
||||
public ConfigModule(string submodule = null)
|
||||
{
|
||||
_submodule = submodule;
|
||||
}
|
||||
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
// We're assuming IConfiguration is already available somehow - it comes from various places (auto-injected in ASP, etc)
|
||||
|
||||
// Register the CoreConfig and where to find it
|
||||
builder.Register(c => c.Resolve<IConfiguration>().GetSection("PluralKit").Get<CoreConfig>() ?? new CoreConfig()).SingleInstance();
|
||||
|
||||
// Register the submodule config (BotConfig, etc) if specified
|
||||
if (_submodule != null)
|
||||
builder.Register(c => c.Resolve<IConfiguration>().GetSection("PluralKit").GetSection(_submodule).Get<T>() ?? new T()).SingleInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue