﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Gabor Ratky commented on Dependency Injection in Web Forms MVC</title><description>Ayende,
  
  
You point out that WSCF's (and for WinForms, SCSF's -&gt; Composite UI App. Block) [CreateNew] pattern ties the lifecycle of the presenter to the lifecylce of ASP.NET pages and what if you want a single instance for multiple requests, including the postbacks. I think this is perfectly understandable but as soon as you are persisting state between multiple requests in your presenter/controller, you are now have two places where your model/state lives, your controllers and the ASP.NET session state. Of course, you could ignore the built-in session sate altogether but how would that then work with multiple pages?
  
  
You could also rely on a workflow engine to transition between pages and pass the state using that. That would be fairly clean and I like that, although suddenly you're doing the housekeeping of your controller per session per user pattern.
  
  
I would be interested how this is implemented in your BasePage and where do you exactly intercept.
  
  
Good post as always!
</description><link>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment6</link><guid>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment6</guid><pubDate>Sat, 14 Jul 2007 16:08:07 GMT</pubDate></item><item><title>Ayende Rahien commented on Dependency Injection in Web Forms MVC</title><description>&gt; I'm currently in the process of adapting NMVP to Monorail as to give Monorail
  
  
This sounds interesting, let us take the discussion to castle-dev list, okay?
</description><link>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment5</link><guid>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment5</guid><pubDate>Sat, 30 Jun 2007 19:04:49 GMT</pubDate></item><item><title>Bernardo Heynemann commented on Dependency Injection in Web Forms MVC</title><description>I'm sorry but the post was too long for the comments I think.
  
  
Here's how you'd initialize this host:
  
  
SecurityContextMock sec = new SecurityContextMock(); //Security for your App.
  
  
//Create mocks
  
IHost host = MockFactory.CreateHostMock();
  
host.CurrentCathegory = "ProjectForm";
  
  
IProjectDetails pdm = MockFactory.CreateViewMock&lt;IProjectDetails&gt;();
  
IProjectMembers pmm = MockFactory.CreateContainerMock&lt;IProjectMembers, ProjectMemberPresenter&gt;();
  
  
//Inject mocks into the Windsor container as instances of contracts
  
ContractViewCollection models = new ContractViewCollection();
  
models.Add(typeof(IProjectDetails), pdm);
  
models.Add(typeof(IProjectMembers), pmm);
  
  
//Resolve everything.			
  
Resolver container = Resolver.Get(sec, host, models, confPath);
  
presenter = container.GetHostPresenter();		
  
  
//Indicates that our views should be in editable mode.
  
presenter.SetEditableMode();
  
  
//Perform initialization and loading (this part calls all children 
  
//presenters init and load methods, that act on their individual views).
  
presenter.Init(true);
  
presenter.Load(true);
  
  
Please notice that this code is the same no matter which platform you're in, with the only difference being the mocks part (in ASP.Net you'd provide user controls, same with Windows Forms, etc).
  
  
Hope to be hearing from you soon! :) BTW, Thanks for all the work.
</description><link>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment4</link><guid>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment4</guid><pubDate>Sat, 30 Jun 2007 19:02:12 GMT</pubDate></item><item><title>Bernardo Heynemann commented on Dependency Injection in Web Forms MVC</title><description>Hi Ayende,
  
I'm not sure if you're familiar with (probably not hehehe), but I maintain an open-source project called NMVP, which is a Model-View-Presenter framework to use with whatever view engine you'd like (since MVP is actually view independent). You can check it out at http://www.codeplex.com/nmvp.
  
  
Well I faced the same problem you describe in this post. How to hook every single presenter that composes my form without having to do it manually. So I choose to use Windsor indirectly. The user of NMVP creates a xml file that says:
  
&lt;configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  
               xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  
               presentersMustOverrideInit="true" 
  
               presentersMustOverrideLoad="true" 
  
               presentersMustOverrideSave="true" 
  
               onlyProcessCurrentCathegory="true"&gt;
  
  &lt;triads&gt;
  
    &lt;triad category="Presenter Category" 
  
              contract="full name"
  
              presenter="full name" /&gt;
  
  &lt;/triad&gt;
  
&lt;/configuration&gt;
  
  
This way when you create the Host page (the one that will call the HostPresenter.Initialize method passing the path to this file, sort of) I configure a dynamic windsor container with the definitions of the xml file, inject every single user control (or whatever you'd like) as implementations of each contract and let Windsor resolve the rest for me.
  
  
I'd really like some insight from you in this subject. I'm currently in the process of adapting NMVP to Monorail as to give Monorail a MVP approach, allowing MonoRail users to use several views / presenters per action (composable views).
</description><link>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment3</link><guid>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment3</guid><pubDate>Sat, 30 Jun 2007 18:56:12 GMT</pubDate></item><item><title>Fredrik Norm&amp;#233;n commented on Dependency Injection in Web Forms MVC</title><description>I prefer to use Dave Newman solution, here is an post on my blog how I implement the MVP pattern in ASP.Net:
  
  
http://fredrik.nsquared2.com/ViewPost.aspx?PostID=416
  
  
The view is passed into the "presenter/controller".
  
  
I have also a post where I extend it to make sure the "presenter/controller" can handle the state and navigation for us:
  
  
http://fredrik.nsquared2.com/ViewPost.aspx?PostId=419
  
  
The solution I use is also prepared to inject the presenter to the View. I had a framework that I build where I could in an XML file specify a view and a presenter to the view. When I navigate to the View the framework injects the specified presenter to the view. By doing this I could easy change the presenter of a view by only modifying the XML file.
</description><link>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment2</link><guid>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment2</guid><pubDate>Thu, 28 Jun 2007 09:04:41 GMT</pubDate></item><item><title>Dave Newman commented on Dependency Injection in Web Forms MVC</title><description>An inbetween solution is to have the presenters resolved in a base class.  This is what my MVP setup looks like:
  
  
public class PresentedPage&lt;TPresenter&gt; : Page
  
{
  
    protected TPresenter _presenter;
  
  
    protected override void OnInit(EventArgs e)
  
    {
  
        base.OnInit(e);
  
        _presenter = IoC.ResolvePresenter&lt;TPresenter&gt;(this);
  
    }
  
  
    protected override void OnLoad(EventArgs e)
  
    {
  
        _presenter.PageLoaded(IsPostBack, Request.QueryString);
  
    }
  
}
  
  
and then the page  would look something like this:
  
  
public partial class Home_Index : PresentedPage&lt;Home_Index_Presenter&gt;, IHome_Index_View
  
{
  
    public IList&lt;ResourceCategory&gt; Categories
  
    {
  
        set { DataControlExt.BindControl(_ddlCategories, value); }
  
    }
  
}
  
  
  
If anyone's interested the IoC looks like this:
  
    public class IoC
  
    {
  
        public static TPresenter ResolvePresenter&lt;TPresenter&gt;(object view)
  
        {
  
            Hashtable deps = new Hashtable();
  
            deps.Add("view", view);
  
            return ((IContainerAccessor)HttpContext.Current.ApplicationInstance).Container
  
                .Resolve&lt;TPresenter&gt;(deps);
  
        }
  
    }
  
  
because my presenters take a view interface as a constructor.
  
</description><link>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment1</link><guid>http://ayende.com/2605/dependency-injection-in-web-forms-mvc#comment1</guid><pubDate>Thu, 28 Jun 2007 02:29:50 GMT</pubDate></item></channel></rss>