mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-19 02:46:35 -05:00
28 lines
985 B
C#
28 lines
985 B
C#
using System.Linq;
|
|
using Autofac;
|
|
using OpenDiablo2.Common.Attributes;
|
|
using OpenDiablo2.Common.Interfaces;
|
|
|
|
namespace OpenDiablo2.Scenes
|
|
{
|
|
public sealed class AutofacModule : Module
|
|
{
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
protected override void Load(ContainerBuilder builder)
|
|
{
|
|
log.Info("Configuring OpenDiablo2.Scenes service implementations.");
|
|
|
|
var types = ThisAssembly.GetTypes().Where(x => typeof(IScene).IsAssignableFrom(x) && x.IsClass);
|
|
foreach (var type in types)
|
|
{
|
|
var att = type.GetCustomAttributes(true).First(x => typeof(SceneAttribute).IsAssignableFrom(x.GetType())) as SceneAttribute;
|
|
builder
|
|
.RegisterType(type)
|
|
.Keyed<IScene>(att.SceneName)
|
|
.SingleInstance();
|
|
}
|
|
}
|
|
}
|
|
}
|