forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicAppHost.cs
More file actions
143 lines (111 loc) · 4.3 KB
/
BasicAppHost.cs
File metadata and controls
143 lines (111 loc) · 4.3 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Funq;
using ServiceStack.Html;
using ServiceStack.IO;
using ServiceStack.Server;
using ServiceStack.VirtualPath;
using ServiceStack.ServiceHost;
using ServiceStack.WebHost.Endpoints;
namespace ServiceStack.ServiceInterface.Testing
{
public class BasicAppHost : IAppHost, IHasContainer, IDisposable
{
public BasicAppHost()
{
this.Container = new Container();
this.PreRequestFilters = new List<Action<IHttpRequest, IHttpResponse>>();
this.RequestFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
this.ResponseFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
this.ViewEngines = new List<IViewEngine>();
this.CatchAllHandlers = new List<HttpHandlerResolverDelegate>();
VirtualPathProvider = new FileSystemVirtualPathProvider(this, "~".MapServerPath());
}
public void RegisterAs<T, TAs>() where T : TAs
{
this.Container.RegisterAs<T, TAs>();
}
public virtual void Release(object instance) { }
public void OnEndRequest() {}
public IServiceRoutes Routes { get; private set; }
public void Register<T>(T instance)
{
this.Container.Register(instance);
}
public T TryResolve<T>()
{
return this.Container.TryResolve<T>();
}
public Container Container { get; set; }
public IContentTypes ContentTypeses { get; set; }
public List<Action<IHttpRequest, IHttpResponse>> PreRequestFilters { get; set; }
public List<Action<IHttpRequest, IHttpResponse, object>> RequestFilters { get; set; }
public List<Action<IHttpRequest, IHttpResponse, object>> ResponseFilters { get; set; }
public List<IViewEngine> ViewEngines { get; set; }
public HandleUncaughtExceptionDelegate ExceptionHandler { get; set; }
public HandleServiceExceptionDelegate ServiceExceptionHandler { get; set; }
public List<HttpHandlerResolverDelegate> CatchAllHandlers { get; set; }
public Dictionary<Type, Func<IHttpRequest, object>> RequestBinders
{
get { throw new NotImplementedException(); }
}
private EndpointHostConfig config;
public EndpointHostConfig Config
{
get
{
return config ?? (new EndpointHostConfig("BasicAppHost", new ServiceManager(Container, Assembly.GetExecutingAssembly())));
}
set { config = value; }
}
public void RegisterService(Type serviceType, params string[] atRestPaths)
{
Config.ServiceManager.RegisterService(serviceType);
}
public List<IPlugin> Plugins { get; private set; }
public void LoadPlugin(params IPlugin[] plugins)
{
plugins.ToList().ForEach(x => x.Register(this));
}
public IVirtualPathProvider VirtualPathProvider { get; set; }
public IServiceRunner<TRequest> CreateServiceRunner<TRequest>(ActionContext actionContext)
{
throw new NotImplementedException();
}
public virtual string ResolveAbsoluteUrl(string virtualPath, IHttpRequest httpReq)
{
return httpReq.GetAbsoluteUrl(virtualPath);
}
public BasicAppHost Init()
{
EndpointHost.ConfigureHost(this, GetType().Name, Config.ServiceManager);
return this;
}
private bool disposed;
protected virtual void Dispose(bool disposing)
{
if (disposed) return;
lock (this)
{
if (disposed) return;
if (disposing)
{
if (EndpointHost.Config != null && EndpointHost.Config.ServiceManager != null)
{
EndpointHost.Config.ServiceManager.Dispose();
}
EndpointHost.Dispose();
}
//release unmanaged resources here...
disposed = true;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}