SPRNET-1450
-adjust base class for MvcApplicationContext to WebApplicationContext to acquire proper session scope support
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
|
||||
<spring>
|
||||
<context>
|
||||
<resource uri="~/Config/controllers.xml"/>
|
||||
<resource uri="file://~/Config/controllers.xml"/>
|
||||
</context>
|
||||
</spring>
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Spring.Context.Support
|
||||
/// <summary>
|
||||
/// Application Context for ASP.NET MVC Applications
|
||||
/// </summary>
|
||||
public class MvcApplicationContext : AbstractXmlApplicationContext
|
||||
public class MvcApplicationContext : WebApplicationContext
|
||||
{
|
||||
private readonly string[] _configurationLocations;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.Web.Mvc</RootNamespace>
|
||||
<AssemblyName>Spring.Web.Mvc</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
@@ -66,6 +66,10 @@
|
||||
<Name>Spring.Core.2010</Name>
|
||||
<Private>True</Private>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Spring.Web\Spring.Web.2010.csproj">
|
||||
<Project>{BA4789EB-281A-48EA-8763-28B9F0596A18}</Project>
|
||||
<Name>Spring.Web.2010</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<dependencies>
|
||||
<dependency id="Common.Logging" version="1.2.0" />
|
||||
<dependency id="Spring.Core" version="1.3.1" />
|
||||
<dependency id="Spring.Web" version="1.3.1" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<dependencies>
|
||||
<dependency id="Common.Logging" version="1.2.0" />
|
||||
<dependency id="Spring.Core" version="1.3.1" />
|
||||
<dependency id="Spring.Web" version="1.3.1" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
|
||||
@@ -69,6 +69,14 @@
|
||||
<Project>{5166CE3A-14BE-478A-88DA-729A39DE1E29}</Project>
|
||||
<Name>Spring.Web.Mvc.2010</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\src\Spring\Spring.Web\Spring.Web.2010.csproj">
|
||||
<Project>{BA4789EB-281A-48EA-8763-28B9F0596A18}</Project>
|
||||
<Name>Spring.Web.2010</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Spring.Web.Tests\Spring.Web.Tests.2010.csproj">
|
||||
<Project>{C67E47AA-1ACD-41B4-A465-4D336A2319CA}</Project>
|
||||
<Name>Spring.Web.Tests.2010</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="objects.xml">
|
||||
|
||||
@@ -29,6 +29,7 @@ using Spring.Core.IO;
|
||||
using Spring.Objects.Factory;
|
||||
using Spring.Objects.Factory.Xml;
|
||||
using System.Web.Mvc;
|
||||
using Spring.TestSupport;
|
||||
using Spring.Web.Mvc.Tests.Controllers;
|
||||
using Spring.Context.Support;
|
||||
using System.Reflection;
|
||||
@@ -49,26 +50,29 @@ namespace Spring.Web.Mvc.Tests
|
||||
[SetUp]
|
||||
public void _TestSetup()
|
||||
{
|
||||
ContextRegistry.Clear();
|
||||
_context = new MvcApplicationContext("file://objects.xml");
|
||||
_mvcNamedContext = new MvcApplicationContext("named", false, "file://namedContextObjects.xml");
|
||||
|
||||
ContextRegistry.RegisterContext(_context);
|
||||
ContextRegistry.RegisterContext(_mvcNamedContext);
|
||||
|
||||
_factory = new SpringControllerFactory();
|
||||
|
||||
//due to ridiculous internal methods in DefaultControllerFactory, have to set the ControllerTypeCache using this extension method
|
||||
// see http://stackoverflow.com/questions/727181/asp-net-mvc-system-web-compilation-compilationlock for more info
|
||||
_factory.InitializeWithControllerTypes(new[]
|
||||
using (new VirtualEnvironmentMock("/somedir/some.file", null, null, "/", true))
|
||||
{
|
||||
typeof(FirstContainerRegisteredController),
|
||||
typeof(SecondContainerRegisteredController),
|
||||
typeof(NotInContainerController),
|
||||
typeof(NamedContextController),
|
||||
});
|
||||
ContextRegistry.Clear();
|
||||
_context = new MvcApplicationContext("file://objects.xml");
|
||||
_mvcNamedContext = new MvcApplicationContext("named", false, "file://namedContextObjects.xml");
|
||||
|
||||
SpringControllerFactory.ApplicationContextName = string.Empty;
|
||||
ContextRegistry.RegisterContext(_context);
|
||||
ContextRegistry.RegisterContext(_mvcNamedContext);
|
||||
|
||||
_factory = new SpringControllerFactory();
|
||||
|
||||
//due to ridiculous internal methods in DefaultControllerFactory, have to set the ControllerTypeCache using this extension method
|
||||
// see http://stackoverflow.com/questions/727181/asp-net-mvc-system-web-compilation-compilationlock for more info
|
||||
_factory.InitializeWithControllerTypes(new[]
|
||||
{
|
||||
typeof (FirstContainerRegisteredController),
|
||||
typeof (SecondContainerRegisteredController),
|
||||
typeof (NotInContainerController),
|
||||
typeof (NamedContextController),
|
||||
});
|
||||
|
||||
SpringControllerFactory.ApplicationContextName = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -87,11 +91,13 @@ namespace Spring.Web.Mvc.Tests
|
||||
[Test]
|
||||
public void CanRevertToTypeMatchIfIdMatchUnsuccessful()
|
||||
{
|
||||
MvcApplicationContext context = new MvcApplicationContext("file://objectsMatchByType.xml");
|
||||
|
||||
ContextRegistry.Clear();
|
||||
ContextRegistry.RegisterContext(context);
|
||||
using (new VirtualEnvironmentMock("/somedir/some.file", null, null, "/", true))
|
||||
{
|
||||
MvcApplicationContext context = new MvcApplicationContext("file://objectsMatchByType.xml");
|
||||
|
||||
ContextRegistry.Clear();
|
||||
ContextRegistry.RegisterContext(context);
|
||||
}
|
||||
IController controller = _factory.CreateController(new RequestContext(new MockContext(), new RouteData()), "FirstContainerRegistered");
|
||||
|
||||
Assert.AreEqual("Should_Be_Matched_By_Type", ((FirstContainerRegisteredController)controller).TestValue);
|
||||
|
||||
Reference in New Issue
Block a user