This repository has been archived by the owner on Jun 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartup.cs
60 lines (55 loc) · 1.82 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Web.Http;
using Castle.Windsor;
using Castle.Windsor.Installer;
using GitMerger.Infrastructure;
using GitMerger.Infrastructure.Settings;
using Microsoft.Owin.Hosting;
using Owin;
using WConfiguration = Castle.Windsor.Installer.Configuration;
namespace GitMerger
{
public class Startup
{
private static readonly IWindsorContainer _container;
private static readonly IHostSettings _hostSettings;
private static IDisposable _app;
private static bool _isDisposed;
static Startup()
{
_container = new WindsorContainer()
// app.config first, so we can override registrations if we want/have to
.Install(WConfiguration.FromAppConfig(), FromAssembly.This());
_hostSettings = _container.Resolve<IHostSettings>();
}
/// <summary>
/// Starts a WebApi Service and returns the base address used.
/// </summary>
/// <returns>The base address of the service</returns>
public static string Start()
{
_app = WebApp.Start<Startup>(_hostSettings.BaseAddress);
return _hostSettings.BaseAddress;
}
public static void Shutdown()
{
if (!_isDisposed)
{
_isDisposed = true;
if (_app != null)
{
_app.Dispose();
_app = null;
}
_container.Dispose();
}
}
public void Configuration(IAppBuilder appBuilder)
{
var config = new HttpConfiguration();
config.Routes.MapHttpRoute("GitMerger", "{controller}");
config.DependencyResolver = new CastleDependencyResolver(_container);
appBuilder.UseWebApi(config);
}
}
}