WCFã§Seasar.NETã使ã
ä»éçºä¸ã®ããã±ã¼ã¸ã¯Webãµã¼ãã¹ã使ã£ã¦ãã¾ãããã¦ã¼ã¶ã®ç°å¢ãã¤ã³ãã©ããããªã³ãªã¼ã ã¨åãã£ã¦ããå ´åã¯ãWebãµã¼ãã¹ã®ãªã¼ãã¼ããããå¿ä½ãªãã®ã§TCP/IPã¨ãã«åºæ¥ãã°ãªããã¨ãæã£ã¦ããããIIS7ã§ã¯Windowsããã»ã¹ã¢ã¯ãã£ãåãµã¼ãã¹(WAS)ã追å ãããããã ã¨IISã§ãTCPãNamed-PipeãMSMQãªã©ã使ãããã¨ãåãã£ã¦ãã¡ãã£ã¨WCFã«èå³ãåºã¦ãã¾ãããæ©éãWCFãIISã§ãã¹ãããã¦ã¿ãã¨ãããASP.NETã¨éã£ã¦Global.aspxç¸å½ã®ãã®ãåå¨ãããDIã³ã³ããã®åæåã¿ã¤ãã³ã°ãã©ãããããæ©ã¿ã¾ããã
調ã¹ã¦ã¿ãã¨ããServiceHostFactoryã«æãå ¥ããã°è¯ããããªã®ã§ã以ä¸ã®ããã«ãã¦ã¿ã¾ããã
using System; using System.ServiceModel; using System.ServiceModel.Activation; using Seasar.Framework.Container.Factory; namespace IISHostDI { public class MyServiceHostFactory : ServiceHostFactoryBase { public override ServiceHostBase CreateServiceHost( string constructorString, Uri[] baseAddresses) { Type service = Type.GetType(constructorString); ServiceHost host = new ServiceHost(service, baseAddresses); // hook up event handlers host.Opening += Opening; host.Closing += Closing; return host; } private static void Opening(object sender, EventArgs e) { SingletonS2ContainerFactory.Init(); } private static void Closing(object sender, EventArgs e) { SingletonS2ContainerFactory.Destroy(); } } }
ãã¨ã¯ãService.svcãã¡ã¤ã«ã«
<%@ ServiceHost Service="IISHostDI.Service1" Factory="IISHostDI.MyServiceHostFactory" %>
ã¨æ¸ãã¦ããã°ãèªä½ããMyServiceHostFactoryãå¼ã°ããDIã³ã³ããã®åæåãèµ°ãã¾ããWCFã«ã¤ãã¦ã¯ãã¾ã ã¾ã 調æ»ä¸è¶³ã§ã³ã¬ã§è¯ãã®ãèªä¿¡ãããã¾ããããä¸å¿ãåèã¾ã§ã«ã