How to Inject controller into UserControls from its Container Page

Topics: Web Client Software Factory, Project Management Forum, UIP Application Block discussion, User Forum
Sep 27, 2008 at 5:57 PM
Edited Sep 27, 2008 at 5:59 PM
Greetings Team,$0First of all thanks for all the help provided through this forum. I learned a lot by going through this post. In the current project I am working on we have page which has multiple user controls in it. For the sake of discussion; say Page1.aspx has UserControls UC1, UC2 and UC3. In the normal webSF pratice or atleast in the last project we used to do is; each of these user controls presenter  has [CreateNew] attribute attached to the controller. So what happens in when the page loads it creates a new instance of the controller and then when the user control loads it creates its own individual controller instances. So the bottom line here is; when the page load is complete there will be (N+1) instances of the Controller class; where N is the number of user controls in the page. One way I saw in the modularity bundle is the user controller view interface expose a property/method to get the reference to the presenter. And inside the presenter class there is another property to do SET and GET the controller. Its works. But here is the issue. With the new current production version; all the contracts (Interface definition) are now moved to a single project named as  *.interfaces. And presenter is implemented in another project which refers back to the contracts definied in the interface project. So the dependency direction is Presenter(module) has a reference to the interface project. But if I follow the MVP Modularity bundle, the in the interface project I need to have a project reference to the presenter implementation. I feel like this is not good; because *.interface project shouldnt need to know the implementation project. So the bottom line question is; how to inject the controller in to the user controls from the page rather than creating multiple instances. At the same time trying to keep the interface project from knowing about its implementation project - where the real presenter is being implemented.$0
Oct 1, 2008 at 1:05 AM
The solution to your issue is to use [CreateShared].