Sonarr/NzbDrone.Services.Api/Bootstrapper.cs

58 lines
1.8 KiB
C#
Raw Normal View History

2013-01-29 01:07:18 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
2013-02-01 04:18:11 +00:00
using AutoMapper;
2013-01-29 01:07:18 +00:00
using Autofac;
2013-02-01 04:18:11 +00:00
using MongoDB.Bson;
2013-01-29 01:07:18 +00:00
using NLog;
using Nancy.Bootstrapper;
using Nancy.Bootstrappers.Autofac;
using NzbDrone.Services.Api.Extensions;
2013-02-01 04:18:11 +00:00
using NzbDrone.Services.Api.SceneMapping;
2013-01-29 01:07:18 +00:00
namespace NzbDrone.Services.Api
{
public class Bootstrapper : AutofacNancyBootstrapper
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
protected override ILifetimeScope GetApplicationContainer()
{
ApplicationPipelines.OnError.AddItemToEndOfPipeline((context, exception) =>
{
Logger.FatalException("Application Exception", exception);
return null;
});
var builder = new ContainerBuilder();
builder.RegisterApiServices();
var container = builder.Build();
return container;
}
protected override NancyInternalConfiguration InternalConfiguration
{
get
{
return NancyInternalConfiguration.WithOverrides(c => c.Serializers.Add(typeof(NancyJsonSerializer)));
2013-01-29 01:07:18 +00:00
}
}
2013-02-01 04:18:11 +00:00
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
InitializeAutomapper();
}
public static void InitializeAutomapper()
{
Mapper.CreateMap<SceneMappingModel, SceneMappingJsonModel>()
.ForMember(dest => dest.MapId, opt => opt.MapFrom(src => src.MapId.ToString()));
Mapper.CreateMap<SceneMappingJsonModel, SceneMappingModel>()
.ForMember(dest => dest.MapId, opt => opt.MapFrom(src => ObjectId.Parse(src.MapId)));
}
2013-01-29 01:07:18 +00:00
}
}