This repository was archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathCastleWindsorAdapter.cs
More file actions
39 lines (35 loc) · 1.45 KB
/
CastleWindsorAdapter.cs
File metadata and controls
39 lines (35 loc) · 1.45 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
namespace Microsoft.AspNet.WebFormsDependencyInjection.CastleWindsor
{
using Castle.Windsor;
using System.Web;
/// <summary>
/// Extension methods of HttpApplication that help use Castle Windsor container
/// </summary>
public static class CastleWindsorAdapter
{
private static object _lock = new object();
/// <summary>
/// Add a new Castle Windsor container in asp.net application. If there is WebObjectActivator already registered,
/// it will be chained up. When the new WebObjectActivator can't resolve the type, the previous WebObjectActivator
/// will be used. If the previous WebObjectActivator can't resolve it either, DefaultCreateInstance will be used
/// which creates instance through none public default constructor based on reflection.
/// </summary>
/// <returns></returns>
public static IWindsorContainer AddCastleWindsor()
{
lock (_lock)
{
HttpRuntime.WebObjectActivator = new ContainerServiceProvider(HttpRuntime.WebObjectActivator);
return GetContainer();
}
}
/// <summary>
/// Get most recent added Castle Windsor container
/// </summary>
/// <returns></returns>
public static IWindsorContainer GetContainer()
{
return (HttpRuntime.WebObjectActivator as ContainerServiceProvider)?.Container;
}
}
}