diff --git a/examples/Spring/Spring.Mvc3QuickStart/src/Spring.Mvc3QuickStart/Web.config b/examples/Spring/Spring.Mvc3QuickStart/src/Spring.Mvc3QuickStart/Web.config index e88a3b6a..661646ca 100644 --- a/examples/Spring/Spring.Mvc3QuickStart/src/Spring.Mvc3QuickStart/Web.config +++ b/examples/Spring/Spring.Mvc3QuickStart/src/Spring.Mvc3QuickStart/Web.config @@ -25,7 +25,7 @@ - + diff --git a/src/Spring/Spring.Web.Mvc3/Context/Support/MvcContextHandler.cs b/src/Spring/Spring.Web.Mvc3/Context/Support/MvcContextHandler.cs index cfadc4bb..b235ac56 100644 --- a/src/Spring/Spring.Web.Mvc3/Context/Support/MvcContextHandler.cs +++ b/src/Spring/Spring.Web.Mvc3/Context/Support/MvcContextHandler.cs @@ -29,35 +29,8 @@ namespace Spring.Context.Support /// /// Context Handler for ASP.NET MVC Applications /// - public class MvcContextHandler : ContextHandler + public class MvcContextHandler : WebContextHandler { - /// - /// The of - /// created if no type attribute is specified on a context element. - /// - /// - protected override Type DefaultApplicationContextType - { - get { return typeof(MvcApplicationContext); } - } - - - /// - /// Get the context's case-sensitivity to use if none is specified - /// - /// - /// - ///

- /// Derived handlers may override this property to change their default case-sensitivity. - ///

- ///

- /// Defaults to 'true'. - ///

- ///
- protected override bool DefaultCaseSensitivity - { - get { return false; } - } } } diff --git a/src/Spring/Spring.Web.Mvc3/Spring.Web.Mvc3.2010.csproj b/src/Spring/Spring.Web.Mvc3/Spring.Web.Mvc3.2010.csproj index 3f687926..d3e926b4 100644 --- a/src/Spring/Spring.Web.Mvc3/Spring.Web.Mvc3.2010.csproj +++ b/src/Spring/Spring.Web.Mvc3/Spring.Web.Mvc3.2010.csproj @@ -65,6 +65,10 @@ Spring.Core.2010 True + + {BA4789EB-281A-48EA-8763-28B9F0596A18} + Spring.Web.2010 + diff --git a/src/Spring/Spring.Web.Mvc3/SpringMvcApplication.cs b/src/Spring/Spring.Web.Mvc3/SpringMvcApplication.cs index be1d7851..44b35f16 100644 --- a/src/Spring/Spring.Web.Mvc3/SpringMvcApplication.cs +++ b/src/Spring/Spring.Web.Mvc3/SpringMvcApplication.cs @@ -47,7 +47,29 @@ namespace Spring.Web.Mvc //the Spring HTTP Module won't have built the context for us until now so we have to delay until the init ConfigureApplicationContext(); - RegisterResolver(); + } + + /// + /// Handles the BeginRequest event of the Application control. + /// + /// The source of the event. + /// The instance containing the event data. + protected virtual void Application_BeginRequest(object sender, EventArgs e) + { + var resolver = BuildDependencyResolver(); + RegisterDependencyResolver(resolver); + } + + + /// + /// Builds the dependency resolver. + /// + /// The instance. + /// You must override this method in a derived class to control the manner in which the + /// is created. + protected virtual IDependencyResolver BuildDependencyResolver() + { + return new SpringMvcDependencyResolver(ContextRegistry.GetContext()); } /// @@ -62,7 +84,6 @@ namespace Spring.Web.Mvc } - /// /// Registers the DependencyResolver implementation with the MVC runtime. /// @@ -70,9 +91,42 @@ namespace Spring.Web.Mvc /// is registered. /// /// - public virtual void RegisterResolver() + public virtual void RegisterDependencyResolver(IDependencyResolver resolver) { - DependencyResolver.SetResolver(new SpringMvcDependencyResolver(ContextRegistry.GetContext())); + ThreadSafeDependencyResolverRegistrar.Register(resolver); + } + + /// + /// Thread-safe class that ensures that the is registered only once. + /// + protected static class ThreadSafeDependencyResolverRegistrar + { + private static bool _isInitialized = false; + private static readonly Object @lock = new Object(); + + /// + /// Registers the specified resolver. + /// + /// The resolver. + public static void Register(IDependencyResolver resolver) + { + if (_isInitialized) + { + return; + } + + lock (@lock) + { + if (_isInitialized) + { + return; + } + + DependencyResolver.SetResolver(resolver); + + _isInitialized = true; + } + } } }