2018-12-08 09:12:40 -05:00
|
|
|
|
/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-11-30 23:37:08 -05:00
|
|
|
|
using System.Linq;
|
2018-11-29 23:26:51 -05:00
|
|
|
|
using Autofac;
|
2018-11-30 23:37:08 -05:00
|
|
|
|
using OpenDiablo2.Common.Attributes;
|
2018-11-29 23:26:51 -05:00
|
|
|
|
using OpenDiablo2.Common.Enums;
|
|
|
|
|
using OpenDiablo2.Common.Interfaces;
|
2018-11-29 22:12:40 -05:00
|
|
|
|
|
|
|
|
|
namespace OpenDiablo2.ServiceBus
|
|
|
|
|
{
|
|
|
|
|
public sealed class AutofacModule : Module
|
|
|
|
|
{
|
|
|
|
|
protected override void Load(ContainerBuilder builder)
|
|
|
|
|
{
|
2018-11-30 23:37:08 -05:00
|
|
|
|
builder.RegisterType<SessionManager>().As<ISessionManager>().InstancePerLifetimeScope();
|
|
|
|
|
builder.RegisterType<SessionServer>().As<ISessionServer>().InstancePerLifetimeScope();
|
|
|
|
|
|
|
|
|
|
var types = ThisAssembly.GetTypes().Where(x => typeof(IMessageFrame).IsAssignableFrom(x) && x.IsClass);
|
|
|
|
|
foreach (var type in types)
|
|
|
|
|
{
|
2018-12-08 13:31:50 -05:00
|
|
|
|
var att = type.GetCustomAttributes(true).First(x => (x is MessageFrameAttribute)) as MessageFrameAttribute;
|
2018-11-30 23:37:08 -05:00
|
|
|
|
builder
|
|
|
|
|
.RegisterType(type)
|
|
|
|
|
.Keyed<IMessageFrame>(att.FrameType)
|
|
|
|
|
.InstancePerDependency();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.Register<Func<eMessageFrameType, IMessageFrame>>(c =>
|
|
|
|
|
{
|
|
|
|
|
var componentContext = c.Resolve<IComponentContext>();
|
|
|
|
|
return (frameType) => componentContext.ResolveKeyed<IMessageFrame>(frameType);
|
|
|
|
|
});
|
2018-11-29 23:26:51 -05:00
|
|
|
|
|
|
|
|
|
builder.Register<Func<eSessionType, ISessionManager>>(c =>
|
|
|
|
|
{
|
|
|
|
|
var componentContext = c.Resolve<IComponentContext>();
|
2018-11-30 23:37:08 -05:00
|
|
|
|
return (sessionType) => componentContext.Resolve<ISessionManager>(new NamedParameter("sessionType", sessionType));
|
2018-11-29 23:26:51 -05:00
|
|
|
|
});
|
2018-11-30 23:37:08 -05:00
|
|
|
|
|
|
|
|
|
builder.Register<Func<eSessionType, ISessionServer>>(c =>
|
|
|
|
|
{
|
|
|
|
|
var componentContext = c.Resolve<IComponentContext>();
|
|
|
|
|
return (sessionType) => componentContext.Resolve<ISessionServer>(new NamedParameter("sessionType", sessionType));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2018-11-29 22:12:40 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|