asp.Netmvc 3ではspringを使用する.net 1.3.1
1参照Commonを追加します.Logging、Spring.Core、Spring.Web、Spring.Web.Mvc
2ウェブを修正する.config
3 globalを変更します.ascx.cs,Application_Start()メソッドにコードを追加
注意:
1 springは使用しないでください.Net公式SpringMvcApplicationクラス、このクラスにはもともとglobalがたくさん含まれています.ascx.csのコードはglobal.ascx.csはSpringMvcApplicationクラスを継承し、globalを調整する必要がある.ascx.csクラスのコード、親コードとの重複と衝突を防止
2実際にControllerでspringを使用してIoCを行うには、ControllerFactoryの実装クラスをSpringControllerFactoryとして登録するだけで、次の2つの方法があります.
a直接Application_スタート()メソッドで呼び出すのは、上記の方法です.
b global.ascx.csのクラスは親を継承し、この親にControllerFactoryを登録します.
2ウェブを修正する.config
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc"/>
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="~/Config/Controllers.xml"/>
</context>
</spring>
3 globalを変更します.ascx.cs,Application_Start()メソッドにコードを追加
ControllerBuilder.Current.SetControllerFactory(typeof(SpringControllerFactory));
注意:
1 springは使用しないでください.Net公式SpringMvcApplicationクラス、このクラスにはもともとglobalがたくさん含まれています.ascx.csのコードはglobal.ascx.csはSpringMvcApplicationクラスを継承し、globalを調整する必要がある.ascx.csクラスのコード、親コードとの重複と衝突を防止
2実際にControllerでspringを使用してIoCを行うには、ControllerFactoryの実装クラスをSpringControllerFactoryとして登録するだけで、次の2つの方法があります.
a直接Application_スタート()メソッドで呼び出すのは、上記の方法です.
b global.ascx.csのクラスは親を継承し、この親にControllerFactoryを登録します.