SPRNET-1443

-add initial support for MVC3 (this will probably break the build until I can uncorrupt my local SVN folder tree and commit the missing pieces -- WORK IN PROGRESS)
This commit is contained in:
sbohlen
2011-05-23 01:35:10 +00:00
parent 86ec218b4e
commit 20b839cf03
17 changed files with 992 additions and 1 deletions

View File

@@ -78,6 +78,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Data.NHibernate31.20
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Data.NHibernate31.Tests.2010", "test\Spring\Spring.Data.NHibernate31.Tests\Spring.Data.NHibernate31.Tests.2010.csproj", "{867628D8-DFCC-4D2A-A786-EB0D97DBC3DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Web.Mvc3.2010", "src\Spring\Spring.Web.Mvc3\Spring.Web.Mvc3.2010.csproj", "{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Web.Mvc3.Tests.2010", "test\Spring\Spring.Web.Mvc3.Tests\Spring.Web.Mvc3.Tests.2010.csproj", "{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|.NET = Debug|.NET
@@ -458,6 +462,26 @@ Global
{867628D8-DFCC-4D2A-A786-EB0D97DBC3DC}.Release|Any CPU.Build.0 = Release|Any CPU
{867628D8-DFCC-4D2A-A786-EB0D97DBC3DC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{867628D8-DFCC-4D2A-A786-EB0D97DBC3DC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}.Debug|.NET.ActiveCfg = Debug|Any CPU
{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}.Release|.NET.ActiveCfg = Release|Any CPU
{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}.Release|Any CPU.Build.0 = Release|Any CPU
{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}.Debug|.NET.ActiveCfg = Debug|Any CPU
{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}.Release|.NET.ActiveCfg = Release|Any CPU
{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}.Release|Any CPU.Build.0 = Release|Any CPU
{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}.Release|Mixed Platforms.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -116,7 +116,7 @@ namespace Spring.Web.Mvc
var controllers = ApplicationContext.GetObjectsOfType(controllerType);
if (controllers.Count > 0)
{
controller = (IController)controllers.Cast<DictionaryEntry>().First<DictionaryEntry>().Value;
controller = (IController)controllers.Cast<DictionaryEntry>().First().Value;
}
}
else

View File

@@ -0,0 +1,148 @@
#region License
/*
* Copyright © 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context.Support;
using Spring.Core.IO;
namespace Spring.Context.Support
{
/// <summary>
/// Application Context for ASP.NET MVC Applications
/// </summary>
public class MvcApplicationContext : AbstractXmlApplicationContext
{
private readonly string[] _configurationLocations;
private readonly IResource[] _configurationResources;
/// <summary>
/// Create a new MvcApplicationContext, 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 MvcApplicationContext(string name, bool caseSensitive, params string[] configurationLocations)
: this(new MvcApplicationContextArgs(name, null, configurationLocations, null, caseSensitive))
{
}
/// <summary>
/// Create a new MvcApplicationContext 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 MvcApplicationContext(string name, bool caseSensitive, IApplicationContext parentContext,
params string[] configurationLocations)
: this(new MvcApplicationContextArgs(name, parentContext, configurationLocations, null, caseSensitive))
{ }
/// <summary>
/// Initializes a new instance of the <see cref="MvcApplicationContext"/> class.
/// </summary>
/// <param name="args">The args.</param>
public MvcApplicationContext(MvcApplicationContextArgs args)
: base(args.Name, args.CaseSensitive, args.ParentContext)
{
_configurationLocations = args.ConfigurationLocations;
_configurationResources = args.ConfigurationResources;
Refresh();
if (log.IsDebugEnabled)
{
log.Debug("created instance " + this.ToString());
}
}
/// <summary>
/// Create a new MvcApplicationContext, 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>
/// <param name="configurationResources">Configuration resources.</param>
public MvcApplicationContext(string name, bool caseSensitive, string[] configurationLocations, IResource[] configurationResources)
: this(new MvcApplicationContextArgs(name, null, configurationLocations, configurationResources, caseSensitive))
{
}
/// <summary>
/// Create a new MvcApplicationContext, loading the definitions
/// from the given XML resource.
/// </summary>
/// <param name="configurationLocations">Names of configuration resources.</param>
public MvcApplicationContext(params string[] configurationLocations)
: this(new MvcApplicationContextArgs(string.Empty, null, configurationLocations, null, false))
{
}
/// <summary>
/// An array of resource locations, referring to the XML object
/// definition files that this context is to be built with.
/// </summary>
/// <value></value>
/// <remarks>
/// <p>
/// Examples of the format of the various strings that would be
/// returned by accessing this property can be found in the overview
/// documentation of with the <see cref="XmlApplicationContext"/>
/// class.
/// </p>
/// </remarks>
/// <returns>
/// An array of resource locations, or <see langword="null"/> if none.
/// </returns>
protected override string[] ConfigurationLocations
{
get { return _configurationLocations; }
}
/// <summary>
/// An array of resources that this context is to be built with.
/// </summary>
/// <value></value>
/// <remarks>
/// <p>
/// Examples of the format of the various strings that would be
/// returned by accessing this property can be found in the overview
/// documentation of with the <see cref="XmlApplicationContext"/>
/// class.
/// </p>
/// </remarks>
/// <returns>
/// An array of <see cref="Spring.Core.IO.IResource"/>s, or <see langword="null"/> if none.
/// </returns>
protected override IResource[] ConfigurationResources
{
get { return _configurationResources; }
}
}
}

View File

@@ -0,0 +1,76 @@
#region License
/*
* Copyright © 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using Spring.Core.IO;
namespace Spring.Context.Support
{
/// <summary>
/// Encapsulates arguments to the <see cref="Spring.Context.Support.MvcApplicationContext"/> class.
/// </summary>
public class MvcApplicationContextArgs : AbstractXmlApplicationContextArgs
{
private const bool DEFAULT_CASESENSITIVE = false;
private const bool DEFAULT_REFRESH = false;
/// <summary>
/// Initializes a new instance of the MvcApplicationContextArgs class.
/// </summary>
public MvcApplicationContextArgs()
{
CaseSensitive = DEFAULT_CASESENSITIVE;
}
/// <summary>
/// Initializes a new instance of the MvcApplicationContextArgs class.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="parentContext">The parent context.</param>
/// <param name="configurationLocations">The configuration locations.</param>
/// <param name="configurationResources">The configuration resources.</param>
public MvcApplicationContextArgs(string name, IApplicationContext parentContext, string[] configurationLocations, IResource[] configurationResources)
: this(name, parentContext, configurationLocations, configurationResources, DEFAULT_CASESENSITIVE)
{ }
/// <summary>
/// Initializes a new instance of the MvcApplicationContextArgs class.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="parentContext">The parent context.</param>
/// <param name="configurationLocations">The configuration locations.</param>
/// <param name="configurationResources">The configuration resources.</param>
/// <param name="caseSensitive">if set to <c>true</c> [case sensitive].</param>
public MvcApplicationContextArgs(string name, IApplicationContext parentContext, string[] configurationLocations, IResource[] configurationResources, bool caseSensitive)
{
Name = name;
ParentContext = parentContext;
ConfigurationLocations = configurationLocations;
ConfigurationResources = configurationResources;
CaseSensitive = caseSensitive;
Refresh = DEFAULT_REFRESH;
}
}
}

View File

@@ -0,0 +1,63 @@
#region License
/*
* Copyright © 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context.Support;
namespace Spring.Context.Support
{
/// <summary>
/// Context Handler for ASP.NET MVC Applications
/// </summary>
public class MvcContextHandler : ContextHandler
{
/// <summary>
/// The <see cref="System.Type"/> of <see cref="Spring.Context.IApplicationContext"/>
/// created if no <c>type</c> attribute is specified on a <c>context</c> element.
/// </summary>
/// <value></value>
protected override Type DefaultApplicationContextType
{
get { return typeof(MvcApplicationContext); }
}
/// <summary>
/// Get the context's case-sensitivity to use if none is specified
/// </summary>
/// <value></value>
/// <remarks>
/// <p>
/// Derived handlers may override this property to change their default case-sensitivity.
/// </p>
/// <p>
/// Defaults to 'true'.
/// </p>
/// </remarks>
protected override bool DefaultCaseSensitivity
{
get { return false; }
}
}
}

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Spring.Web.Mvc</RootNamespace>
<AssemblyName>Spring.Web.Mvc3</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\build\VS.Net.2010\Spring.Web.Mvc3\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET_3_5;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>Spring.Web.Mvc3.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Common.Logging">
<HintPath>..\..\..\lib\Net\3.5\Common.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Context\Support\MvcApplicationContext.cs" />
<Compile Include="Context\Support\MvcApplicationContextArgs.cs" />
<Compile Include="Context\Support\MvcContextHandler.cs" />
<Compile Include="SpringMvcDependencyResolver.cs" />
<Compile Include="SpringMvcApplication.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Spring.Core\Spring.Core.2010.csproj">
<Project>{710961A3-0DF4-49E4-A26E-F5B9C044AC84}</Project>
<Name>Spring.Core.2010</Name>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,79 @@
#region License
/*
* Copyright © 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Spring.Objects.Factory;
using Spring.Core.IO;
using Spring.Objects.Factory.Xml;
using System.Web.Routing;
using Spring.Context.Support;
namespace Spring.Web.Mvc
{
/// <summary>
/// Spring.NET-specific HttpApplication for ASP.NET MVC integration.
/// </summary>
public abstract class SpringMvcApplication : HttpApplication
{
/// <summary>
/// Executes custom initialization code after all event handler modules have been added.
/// </summary>
public override void Init()
{
base.Init();
//the Spring HTTP Module won't have built the context for us until now so we have to delay until the init
ConfigureApplicationContext();
RegisterResolver();
}
/// <summary>
/// Configures the <see cref="Spring.Context.IApplicationContext"/> instance.
/// </summary>
/// <remarks>
/// You must override this method in a derived class to control the manner in which the
/// <see cref="Spring.Context.IApplicationContext"/> is configured.
/// </remarks>
protected virtual void ConfigureApplicationContext()
{
}
/// <summary>
/// Registers the DependencyResolver implementation with the MVC runtime.
/// <remarks>
/// You must override this method in a derived class to control the manner in which the
/// <see cref="SpringMvcDependencyResolver"/> is registered.
/// </remarks>
/// </summary>
public virtual void RegisterResolver()
{
DependencyResolver.SetResolver(new SpringMvcDependencyResolver(ContextRegistry.GetContext()));
}
}
}

View File

@@ -0,0 +1,95 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Spring.Context;
using Spring.Context.Support;
namespace Spring.Web.Mvc
{
/// <summary>
/// Spring-based implementation of the <see cref="IDependencyResolver"/> interface.
/// </summary>
public class SpringMvcDependencyResolver : IDependencyResolver
{
private IApplicationContext _context;
/// <summary>
/// Initializes a new instance of the <see cref="SpringMvcDependencyResolver"/> class.
/// </summary>
/// <param name="context">The context.</param>
public SpringMvcDependencyResolver(IApplicationContext context)
{
_context = context;
}
/// <summary>
/// Gets the application context.
/// </summary>
/// <value>The application context.</value>
public IApplicationContext ApplicationContext
{
get
{
if (_context == null || _context.Name != ApplicationContextName)
{
if (string.IsNullOrEmpty(ApplicationContextName))
{
_context = ContextRegistry.GetContext();
}
else
{
_context = ContextRegistry.GetContext(ApplicationContextName);
}
}
return _context;
}
}
/// <summary>
/// Gets or sets the name of the application context.
/// </summary>
/// <remarks>
/// Defaults to using the root (default) Application Context.
/// </remarks>
/// <value>The name of the application context.</value>
public static string ApplicationContextName { get; set; }
/// <summary>
/// Resolves singly registered services that support arbitrary object creation.
/// </summary>
/// <param name="serviceType">The type of the requested service or object.</param>
/// <returns>The requested service or object.</returns>
public object GetService(Type serviceType)
{
object service = null;
if (serviceType != null)
{
var services = ApplicationContext.GetObjectsOfType(serviceType);
if (services.Count > 0)
{
service = services.Cast<DictionaryEntry>().First().Value;
}
}
return service;
}
/// <summary>
/// Resolves multiply registered services.
/// </summary>
/// <param name="serviceType">The type of the requested services.</param>
/// <returns>The requested services.</returns>
public IEnumerable<object> GetServices(Type serviceType)
{
var services = ApplicationContext.GetObjectsOfType(serviceType);
return services.Cast<object>();
}
}
}

View File

@@ -0,0 +1,65 @@
#region License
/*
* Copyright <20> 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Web;
using System.Web.Routing;
using Spring.Core.IO;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
using System.Web.Mvc;
using Spring.Web.Mvc.Tests.Controllers;
using Spring.Context.Support;
using System.Reflection;
namespace Spring.Web.Mvc.Tests
{
public static class ControllerFactoryTestExtension
{
private static readonly PropertyInfo _typeCacheProperty;
private static readonly FieldInfo _cacheField;
static ControllerFactoryTestExtension()
{
_typeCacheProperty = typeof(DefaultControllerFactory).GetProperty("ControllerTypeCache", BindingFlags.Instance | BindingFlags.NonPublic);
_cacheField = _typeCacheProperty.PropertyType.GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance);
}
/// <summary>
/// Replaces the cache field of a the DefaultControllerFactory's ControllerTypeCache.
/// This ensures that only the specified controller types will be searched when instantiating a controller.
/// As the ControllerTypeCache is internal, this uses some reflection hackery.
/// </summary>
public static void InitializeWithControllerTypes(this IControllerFactory factory, params Type[] controllerTypes)
{
var cache = controllerTypes
.GroupBy(t => t.Name.Substring(0, t.Name.Length - "Controller".Length), StringComparer.OrdinalIgnoreCase)
.ToDictionary(g => g.Key, g => g.ToLookup(t => t.Namespace ?? string.Empty, StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase);
var buildManager = _typeCacheProperty.GetValue(factory, null);
_cacheField.SetValue(buildManager, cache);
}
}
}

View File

@@ -0,0 +1,31 @@
#region License
/*
* Copyright © 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Web;
using System.Web.Mvc;
namespace Spring.Web.Mvc.Tests.Controllers
{
public class FirstContainerRegisteredController : Controller
{
public string TestValue { get; set; }
}
}

View File

@@ -0,0 +1,31 @@
#region License
/*
* Copyright © 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Web;
using System.Web.Mvc;
namespace Spring.Web.Mvc.Tests.Controllers
{
public class NamedContextController : Controller
{
}
}

View File

@@ -0,0 +1,31 @@
#region License
/*
* Copyright © 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Web;
using System.Web.Mvc;
namespace Spring.Web.Mvc.Tests.Controllers
{
public class NotInContainerController : Controller
{
}
}

View File

@@ -0,0 +1,32 @@
#region License
/*
* Copyright © 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Web;
using System.Web.Mvc;
namespace Spring.Web.Mvc.Tests.Controllers
{
public class SecondContainerRegisteredController : Controller
{
}
}

View File

@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{1E8E7C0A-4474-44F6-AA67-FABB40FA9784}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Spring.Web.Mvc3.Tests</RootNamespace>
<AssemblyName>Spring.Web.Mvc3.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\build\VS.Net.2010\Spring.Web.Mvc3.Tests\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET_3_5;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\..\lib\Net\2.0\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ControllerFactoryTestExtension.cs" />
<Compile Include="Controllers\NamedContextController.cs" />
<Compile Include="Controllers\SecondContainerRegisteredController.cs" />
<Compile Include="Controllers\NotInContainerController.cs" />
<Compile Include="Controllers\FirstContainerRegisteredController.cs" />
<Compile Include="SpringMvcDependencyResolverTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spring\Spring.Core\Spring.Core.2010.csproj">
<Project>{710961A3-0DF4-49E4-A26E-F5B9C044AC84}</Project>
<Name>Spring.Core.2010</Name>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\src\Spring\Spring.Web.Mvc3\Spring.Web.Mvc3.2010.csproj">
<Project>{904C97E0-3667-4D12-A55F-6CC2E6F68A0A}</Project>
<Name>Spring.Web.Mvc3.2010</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="objects.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="namedContextObjects.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,116 @@
#region License
/*
* Copyright © 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using NUnit.Framework;
using Spring.Context.Support;
using Spring.Web.Mvc.Tests.Controllers;
namespace Spring.Web.Mvc.Tests
{
// internal class MockContext : HttpContextBase
// {
// }
[TestFixture]
public class SpringMvcDependencyResolverTests
{
#region Setup/Teardown
[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);
_resolver = new SpringMvcDependencyResolver(_context);
SpringMvcDependencyResolver.ApplicationContextName = string.Empty;
}
#endregion
private MvcApplicationContext _context;
private MvcApplicationContext _mvcNamedContext;
private SpringMvcDependencyResolver _resolver;
[Test]
public void CanUseNamedContextToResolveType()
{
SpringMvcDependencyResolver.ApplicationContextName = "named";
var service = _resolver.GetService(typeof (NamedContextController));
Assert.NotNull(service);
}
[Test]
public void CanUseUnnamedContextToResolveType()
{
Assert.That(SpringMvcDependencyResolver.ApplicationContextName, Is.Empty, "PRECONDITION: Resolver has named-context improperly set!");
var service = _resolver.GetService(typeof (FirstContainerRegisteredController));
Assert.NotNull(service);
}
[Test]
public void RequestForNullTypeReturnsNull()
{
var service = _resolver.GetService(null);
Assert.That(service, Is.Null);
}
[Test]
public void CanReturnCollectionOfTypes()
{
var services = _resolver.GetServices(typeof(FirstContainerRegisteredController));
Assert.That(services.Count(), Is.EqualTo(2));
}
[Test]
public void RequestForSingleInstanceOfMultiplyRegisteredTypeReturnsFirstDefinition()
{
var service = (FirstContainerRegisteredController)_resolver.GetService(typeof(FirstContainerRegisteredController));
Assert.That(service.TestValue, Is.EqualTo("First Definition of Type"));
}
[Test]
public void RequestForSingleUndefinedTypeReturnsNull()
{
var service = _resolver.GetService(typeof(NotInContainerController));
Assert.That(service, Is.Null);
}
[Test]
public void RequestForCollectionOfUndefinedTypesReturnsEmptyCollection()
{
var services = _resolver.GetServices(typeof(NotInContainerController));
Assert.That(services, Is.Empty);
}
}
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="NamedContextController" singleton="false" type="Spring.Web.Mvc.Tests.Controllers.NamedContextController, Spring.Web.Mvc3.Tests"/>
</objects>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<!--id/name intentionally excluded from this definition so that we can ensure retrieve-by-type-match works-->
<object singleton="false" type="Spring.Web.Mvc.Tests.Controllers.FirstContainerRegisteredController, Spring.Web.Mvc3.Tests">
<property name="TestValue" value="First Definition of Type" />
</object>
<!--this object defintion matches the controller name that would be retrieved based on the actual request-->
<object id="FirstContainerRegistered" singleton="false" type="Spring.Web.Mvc.Tests.Controllers.FirstContainerRegisteredController, Spring.Web.Mvc3.Tests">
<property name="TestValue" value="Not First Definition of Type" />
</object>
<object id="SecondContainerRegisteredController" singleton="false" type="Spring.Web.Mvc.Tests.Controllers.SecondContainerRegisteredController, Spring.Web.Mvc3.Tests"/>
</objects>