Files
cs5110_multi_agent/BattleFieldSimulator/BattleFieldSimulator.Utilities/BootStrapper.cs
2020-04-19 21:56:56 -06:00

37 lines
1.0 KiB
C#

using System;
using DryIoc;
namespace BattleFieldSimulator
{
public class BootStrapper
{
private static readonly string NoBootstrapperMessage = $"Called {nameof(BootStrapper)} before it existed";
private static BootStrapper _bootStrapper;
private static IContainer _container;
public static BootStrapper Instance =>
_bootStrapper ?? throw new InvalidOperationException(NoBootstrapperMessage);
private BootStrapper(params IModule[] modules)
{
_container = new Container();
foreach (var module in modules)
{
module.Register(_container);
}
foreach (var module in modules)
{
module.Resolve(_container);
}
}
public static BootStrapper BootstrapSystem(params IModule[] modules) =>
_bootStrapper = new BootStrapper(modules);
public T Resolve<T>()
{
return _container.Resolve<T>();
}
}
}