| S2Container.NET TOP page # Using in ASP.NET This page explains steps necessary to use S2Container.NET on ASP.NET platform. Adding S2HttpModule. Editing Global.asax Registering ASP.NET Web Form Automatic Binding of a Request ## Adding S2HttpModule Following class is used to create S2Container in a web application. - Seasar.Framework.Container.Web.S2HttpModule To use S2HttpModule, add the followings to the Web.config file and add S2HttpModule to ASP.NET application. Refer to source/Seasar/Seasar.Framework.Container/Web/Web.config for an example.
        <httpModules>
    	 <add name="S2HttpModule"
    	     type="Seasar.Framework.Container.Web.S2HttpModule, Seasar" />
        </httpModules>
Define S2Container path at configPath element in the seasar section in annotation configuration file. An instance of S2Container may be retrieved after S2HttpModule is started. - Seasar.Framework.Container.Factory.SingletonS2ContainerFactory#GetContainer() When using S2HttpModule, HttpApplication may be accessed as a component named httpApplication. ## Editing Global.asax Edit Global.asax so S2Container is initialized in Application_Start method and destroyed in Application_End method. SingletonS2ContainerFactory class is in Seasar.Framework.Container.Factory namespace. C#
    protected void Application_Start(Object sender, EventArgs e)
    {
        SingletonS2ContainerFactory.Init();
    }

    protected void Application_End(Object sender, EventArgs e)
    {
        SingletonS2ContainerFactory.Destroy();
    }
VB.NET
    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
       SingletonS2ContainerFactory.Init()
    End Sub

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
       SingletonS2ContainerFactory.Destroy();
    End Sub
## Registering ASP.NET Web Form Web form may be use dependecy injection by registering ASP.NET Web form with S2Container.
        <component name="/Path/WebForm1.aspx" instance="outer" />
Specify virtual path to a web form in a name attribute. Specify outer in an instance attribute. (S2Container does not manage Web form instances.) ## Automatic Binding of a Request A component may be automatically bound to a HttpRequest by defining HttpRequest Request { set; } property to a component. Also, define S2HttpModule in Web.config. In a similar manner, HttpResponse and HttpSession may be defined in a propery (set assessor) to automatically bind to a component. Furthermore, HttpRequest, HttpResponse, HttpSessionState, HttpApplication may respectively be bound to request, response, session, httpApplication components. |
Trans. by H.Ozawa | Copyright© 2004-2007, The Seasar Foundation and the others. All rights reserved.