Results 1 to 2 of 2

Thread: New MvcApplicationContext is created for each hit when using MVC 4 in 2.0.0 M1

  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Default New MvcApplicationContext is created for each hit when using MVC 4 in 2.0.0 M1

    Hello:

    I've been playing with 2.0.0M1's support for ASP.NET MVC4. While promising, I think I've run into a critical issue: a new MvcApplicationContext is created for each hit (when using MVC4's WebApi). While I believe the purpose of this is to support the additional scopes, the debugging I've done so far suggests that the new MvcApplicationContext is created with the overall application's WebApplicationContext as the parent ApplicationContext and is given the same config locations as the parent. As such, this new child MvcApplicationContext loads the same config locations and recreates all of objects, including all of your singletons, and never delegates to the parent context. This effectively makes singletons unusable, and effectively binds everything to the request scope (or lower).

    The relevant code which is creating the new MvcApplicationContext is lines 43 to 52 of Spring.Web.Mvc4/SpringWebApiDependencyResolver.cs in master right now.

    I don't have enough experience in Spring.NET to know what the correct fix/workaround is, but I'm willing to experiment if anyone has ideas. If there's agreement that this is a bug, I'd be happy to open-up an issue.

    I might be making a mistake on my end, but I have compared this to the samples and haven't found an obvious problems.

    Thanks in advance!

  2. #2
    Join Date
    Jul 2010
    Posts
    245

    Default

    Thanks for the feedback! Its not (per se) a 'bug' so much as an incomplete implementation of the feature (and yes, this is indeed sort of a distinction without a difference from the POV of a user right now ).

    The behavior in the M1 release was implemented to support nested contexts/scopes but the extension point that would permit a separate configuration being used for the 'child' context isn't there (yet). So that the existing code *worked* at all, we left it as returning the child container with a config matching its parent. The (eventual) intent is for there to be a property setter on the parent SpringWebApiDependencyResolver that permits setting one or more IResource objects or strings pointing to ConfigurationSources (e.g., "file://~/childconfig.xml") that will be used to construct the nested context(s).

    This is expected to take the form of something like the following being added to the SpringWebApiDependencyResolver class ...

    Code:
    public string[]  ChildContextConfigSources { set; }
    public void  AddChildContextConfigSource (string resourceUrl)
    
    public IResource[]  ChildContextConfigResources { set; }
    public void  AddChildContextConfigResource  (IResource resource)
    ...so that you can set these properties/call these methods during the config of the SpringWebApiDependencyResolver by overriding the SpringMvcApplication.ConfigureApplicationContext method.

    With luck, this code (and its assoc. behavior!) will be in the MASTER branch of the repo by week's end (7/6).

    Does this make sense --?

    -Steve B.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •