-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFluentWebApplicationContext.cs
More file actions
79 lines (71 loc) · 3.57 KB
/
FluentWebApplicationContext.cs
File metadata and controls
79 lines (71 loc) · 3.57 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
using System;
using Spring.Context;
using Spring.Context.Support;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;
namespace Spring.FluentContext.Web
{
public class FluentWebApplicationContext : WebApplicationContext
{
public const string SpringConfiguratorKey = "SpringConfigurator";
private IContextConfigurator _configurator;
#region Constructors
/// <summary>
/// Create a new WebApplicationContext, loading the definitions
/// from the given XML resource.
/// </summary>
/// <param name="configurationLocations">Names of configuration resources.</param>
public FluentWebApplicationContext(params string[] configurationLocations)
: base(new WebApplicationContextArgs(string.Empty, null, configurationLocations, null, false))
{
}
/// <summary>
/// Create a new WebApplicationContext, loading the definitions
/// from the given XML resource.
/// </summary>
/// <param name="name">The application context name.</param>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="configurationLocations">Names of configuration resources.</param>
public FluentWebApplicationContext(string name, bool caseSensitive, params string[] configurationLocations)
: base(new WebApplicationContextArgs(name, null, configurationLocations, null, caseSensitive))
{
}
/// <summary>
/// Create a new WebApplicationContext with the given parent,
/// loading the definitions from the given XML resources.
/// </summary>
/// <param name="name">The application context name.</param>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="parentContext">The parent context.</param>
/// <param name="configurationLocations">Names of configuration resources.</param>
public FluentWebApplicationContext(string name, bool caseSensitive, IApplicationContext parentContext,
params string[] configurationLocations)
: base(new WebApplicationContextArgs(name, parentContext, configurationLocations, null, caseSensitive))
{ }
#endregion
protected override void OnPreRefresh()
{
const string prefix = SpringConfiguratorKey + ProtocolSeparator;
for (int i = 0; i < ConfigurationLocations.Length; i++)
{
if (ConfigurationLocations[i].StartsWith(prefix))
{
string configuratorName = ConfigurationLocations[i].Substring(prefix.Length);
ConfigurationLocations[i] = "assembly://Spring.FluentContext.Web/Spring.FluentContext.Web/emptyContext.xml";
_configurator = (IContextConfigurator) Activator.CreateInstance(Type.GetType(configuratorName));
break; // only one configurator supported
}
}
base.OnPreRefresh();
}
/// <summary>
/// This method registers Fluent objects and calls base post processing
/// </summary>
/// <param name="objectFactory"></param>
protected override void PostProcessObjectFactory(IConfigurableListableObjectFactory objectFactory)
{
_configurator?.LoadObjectDefinitions(this);
base.PostProcessObjectFactory(objectFactory);
}
}
}