New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RenderAction #3
Comments
I just found that it will work if I add this to my IoC.Initialize:
However, this does not work:
Obviously, I don't want to have to add every controller by name here. |
I have been able to reproduce this and will look into it. Is there a bit of your last post missing? Both examples are the same. |
Sorry, markdown got me on that code post above. I edited it to show accurately. |
Confirmed that it is nested containers. I adjusted StructureMapDependencyScope as below, and it worked just fine. What I can't figure out is how to make it work with nested containers.
|
Without changing the way RenderAction works, there is no way. I will try to find a work around tomorrow. Thanks for the feedback! -----Original Message----- Confirmed that it is nested containers. I adjusted StructureMapDependencyScope as below, and it worked just fine. What I can't figure out is how to make it work with nested containers.
— |
I've made the change as above and RenderAction is now working, so thanks for that. However, I now have another problem which, I suspect, is related to the change. I have this code in IoC.cs:
Where I have asked for a singleton, it doesn't seem to be working the way I'd expect. It looks like I'm getting a new instance (or at least the constructor is executing) every time the class gets injected. Thoughts welcome! Thanks, Nick |
Is there any chance that your Initialize method is being called twice? I ran into a similar issue that I'm going to post as a separate issue when using both Structuremap.MVC5 and StructureMap.WebApi2. |
It looks like there is no way to use nested containers with RenderAction unless you use |
Can someone explain the purpose and / or benefit of nested containers? This issue was closed, but it still seems to be very relevant since nested containers do NOT work with RenderAction. |
Using nested controllers is recommended as the correct way by the creator of If you would rather not use nested containers, you can easily comment out the use of nested containers in the |
I came across this same problem today. This seems to mostly break MVC, and I'm trying to wrap my head around why the nested containers are necessary. |
The best way to understand what this means is to look at Jeremy Miller's original post on this. |
I believe I have a resolution to this problem. Will test today and push a new version if it's resolved. |
Ok, so I'm running into a problem with the way StructureMap3, Nested Containers and ASP.NET MVC are working, and it's related to this issue.
But here's the problem, The NestedContainer created in this package, is done at the The I was able to fix the behavior to be more inline with what ASP.NET MVC expects by using ChildContainers. Basically just adding a third possible scope resolution to the In an ActionFilter inheriting from Do we know of any concerns from using it in this fashion? Basically, this setup means any dependencies resolved inside of an action have their own ChildContainer. Dependencies requested within the HttpRequest but outside of an action use the NestedContainer, and any Dependencies that are requested outside of an HttpRequest use the Default Container. Any thoughts on this? EDIT: Running into a few issues with containers getting reused on the View for the primary action, using my solution. Trying to sort through them, there's a 'magic' setup here somewhere, just trying to figure out what that is... |
…lers that have RenderAction calls should always be unique, and *not* scoped to the container lifetime (webadvanced/Structuremap.MVC5#3).
@valmont your ControllerConvention solves the issue of the controller not being unique. There is a solution, but I would rather see structuremap solving this issue. on an better level. Reregister your viewengines: SimpleViewPageActivator is a custom class:
|
I solved this issue by using the ControllerConvention, and then creating and using a ViewConvention as well. It's literally a exact copy of the controller convention, swapping the
|
Hi there,
I just started upgrading some projects to MVC5 and discovered your Nuget package. It's been a welcome addition to the toolbox.
It has worked without inicident across most of the projects, but then I hit a project where I'm using Html.RenderAction. This causes an exception with this message:
A single instance of controller 'HomeController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request.
I think that this may have something to do the use of StructureMap's nested containers, but I'm not sure. Have you tried testing this with a [ChildActionOnly] method on the same controller as the page you are calling RenderAction?
Thanks,
Pete
The text was updated successfully, but these errors were encountered: