2025-04-13 20:16:38 +01:00
|
|
|
|
using FSO.Common.Serialization;
|
|
|
|
|
|
using FSO.Server.Database.DA;
|
|
|
|
|
|
using Ninject.Activation;
|
2015-08-15 14:11:07 +01:00
|
|
|
|
using Ninject.Modules;
|
2025-04-13 20:16:38 +01:00
|
|
|
|
using System;
|
2015-08-15 14:11:07 +01:00
|
|
|
|
|
|
|
|
|
|
namespace FSO.Server.Database
|
|
|
|
|
|
{
|
|
|
|
|
|
public class DatabaseModule : NinjectModule
|
|
|
|
|
|
{
|
|
|
|
|
|
public override void Load()
|
|
|
|
|
|
{
|
2025-04-13 20:16:38 +01:00
|
|
|
|
this.Bind<IDAFactory>().ToProvider<DAFactoryProvider>().InSingletonScope();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class DAFactoryProvider : IProvider<IDAFactory>
|
|
|
|
|
|
{
|
|
|
|
|
|
private DatabaseConfiguration Config;
|
|
|
|
|
|
|
|
|
|
|
|
public DAFactoryProvider(DatabaseConfiguration config)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Config = config;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Type Type
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return typeof(IDAFactory);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public object Create(IContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (Config.Engine)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "mysql":
|
|
|
|
|
|
return new MySqlDAFactory(Config);
|
|
|
|
|
|
case "sqlite":
|
|
|
|
|
|
return new SqliteDAFactory(Config);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
throw new NotSupportedException($"Unsupported database engine {Config.Engine}");
|
|
|
|
|
|
}
|
2015-08-15 14:11:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|