ããæ°
ãã¹ã¯ãããã®äžçã«ãšã£ãŠãwcfã¯ãããŒã«ã«ãããã¯ãŒã¯ãšã°ããŒãã«ãããã¯ãŒã¯ã®äž¡æ¹ã§.netã§ã¯ã©ã€ã¢ã³ããšãµãŒããŒã®å¯Ÿè©±ãæŽçããæãäžè¬çãªæ¹æ³ã§ãã æ§æãæè»ã§ã䜿ãããããééçã§ãã
å°ãªããšããããã¹ãã§ãã å®éã«ã¯ãæ°ãããµãŒãã¹ã®è¿œå ã¯æ¥åžžçãªäœæ¥ã§ãã ãµãŒããŒã§æ§æãç»é²ããããšãå¿ããªãã§ãã ãããã¯ã©ã€ã¢ã³ãã§åãããšãè¡ãããããã·ã¯ã©ã¹ãäœæãŸãã¯çæããå¿ èŠããããŸãã æ§æã®ç¶æã¯äžäŸ¿ã§ãã ãµãŒãã¹ãå€æŽãããå Žåã¯ããããã·ã¯ã©ã¹ãå€æŽããå¿ èŠããããŸãã ãŸããIoCã³ã³ãããŒã«ç»é²ããããšãå¿ããªãã§ãã ããã ãããŠãæ°ãããµãŒãã¹çšã®æ°ãããã¹ããè¿œå ããŸãã ãŸããåçŽãªéåææ§ãå¿ èŠã§ãã ãããšã¯å¥ã«ããã¹ãŠãã·ã³ãã«ã§ããããã®ãªã¹ãããã§ã«3åè¿œå ããèšäºã§ããäœãèŠéããŠããªããã©ããã¯ããããŸããã
èªååããæéã ãœãªã¥ãŒã·ã§ã³ã®äœæããwcfãµãŒãã¹ã®åŒã³åºããŸã§ã®æãåçŽãªã·ããªãªã¯ã次ã®ããã«ãªããŸãã
- ã€ã³ã¹ããŒã«ããã±ãŒãžRikrop.Core.Wcf.Unity
- ServiceContractãšãã®å®è£ ãäœæããŸã
- ãµãŒããŒãšã¯ã©ã€ã¢ã³ãã§ãIoCã«1è¡ã®ç»é²ãè¿œå ããŸãïŒæ§æãç·šéããå¿ èŠã¯ãããŸããïŒ
- 2è¡ãããã¹ããäžãã
var assembly = Assembly.GetExecutingAssembly(); _serviceHostManager.StartServices(assembly);
- ã¯ã©ã€ã¢ã³ãã§ãIServiceExecutor <TService>ã解決ããŸãã ãã®ã©ãããŒã¯ããµãŒãã¹ã®ã¡ãœãããåŒã³åºãã®ã«åœ¹ç«ã¡ããã£ãã«ã§ã®äœæ¥ãé ããŸãã
- 䜿çšã§ããŸã
var articles = await _myServiceExecutor.Execute(service => service.GetArticles());
ã¯ã€ãã¯ã¹ã¿ãŒã
ã¯ã©ã€ã¢ã³ã/ãµãŒããŒã¢ããªã±ãŒã·ã§ã³ãäœæããŸãã ã¯ã©ã€ã¢ã³ãã¯ãæ°å€ã®ã€ã³ããã¯ã¹ããã£ããããæ°åãããµãŒããŒã«æž¡ãããµãŒããŒã¯æå®ãããã€ã³ããã¯ã¹ãæã€æ°åãã·ãŒã±ã³ã¹ããè¿ããŸãã ãã®ã³ã°ãšãšã©ãŒåŠçã¯èšäºã®ã³ãŒãããåé€ãããŸãããã githubã®ã³ãŒãã§ã¯å šäœçãªã¢ãããŒãã説æããããå®å šãªäŸã瀺ããŸãã
çŸå®ã«è¿ããããžã§ã¯ãæ§é ïŒ
Server.Contractsã«ã¯ãwcfãµãŒãã¹ã®ã€ã³ã¿ãŒãã§ã€ã¹ãServer-ãããã®å®è£ ãããã³hoster-wcfãµãŒãã¹ãçºçãããã¯ã©ã¹ã®å®è£ ãå«ãŸããŠããŸãã BL-ãµãŒããŒããžãã¯ã ConsoleServiceHostã¯ãã³ã³ãœãŒã«ã¢ããªã±ãŒã·ã§ã³ãã¡ã€ã³ã§ãµãŒãã¹ããã¹ãããŸãã Client.Presentaionã«ã¯ã察å¿ããã¯ã©ã€ã¢ã³ãå±€ãå«ãŸããŠããŸãã ãã®äŸã§ã¯ããµãŒãã¹åŒã³åºãã³ãã³ããšçµæã®åŠçã®ã¿ããããŸãã ã¯ã©ã€ã¢ã³ãã¯ã以åã®ã¢ã»ã³ããªã䜿çšããŠãŠãŒã¶ãŒå ¥åãåŠçããã³ã³ãœãŒã«ã¢ããªã±ãŒã·ã§ã³ã§ãã
å®éã«ã¯ãnugetããã±ãŒãžã¯æ¬¡ã®ããã«ã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã
- Rikrop.Core.Wcf.Unityã«ã¯ãwcfãæ©èœããããã«å¿ èŠãªã€ã³ãã©ã¹ãã©ã¯ãã£ãIoCã³ã³ãããŒã«ç»é²ããããã®ãã«ããŒãå«ãŸããŠããŸãã ããã¯ã察話ã®ããããåŽé¢ãè¿ éã«ã«ã¹ã¿ãã€ãºããããã®ã¿ãŒã³ããŒãœãªã¥ãŒã·ã§ã³ãšæ¡åŒµæ©èœã®ã»ããã§ãã ããã±ãŒãžã¯ãIoCã³ã³ãããŒã«ãµãŒããŒãšã¯ã©ã€ã¢ã³ãã®ç»é²ããããããžã§ã¯ãã«è¿œå ããå¿ èŠããããŸãã ãã®RikropWcfExample.ServerãšRikropWcfExample.ClientããããŸãã
- Rikrop.Core.Wcfã«ã¯ãwcfããã£ãã«ç®¡çãã»ãã·ã§ã³ãèªèšŒãwcfãµãŒãã¹ã®ãã¹ãã£ã³ã°ãæäœããããã®ã¡ã€ã³ã¯ã©ã¹ãå«ãŸããŠããŸãã ãããRikropWcfExample.Serverã«è¿œå ãããšããã¹ããšRikropWcfExample.Client.Presentation *ããããããããwcfãµãŒãã¹ãåŒã³åºãããŸãã
RikropWcfExample.Server.Contractsã§ã wcfãµãŒãã¹ã®èª¬æãè¿œå ããŸã ã
using System.ServiceModel; using System.Threading.Tasks; namespace RikropWcfExample.Server.Contracts { [ServiceContract] public interface ICalculatorService { [OperationContract] Task<ulong> GetFibonacciNumber(int n); } }
CalculatorService.csã®å®è£ ã¯ããªã¯ãšã¹ããæž¡ããããžãã¹ããžãã¯ã¬ã€ã€ãŒããçµæãè¿ããŸãã
using RikropWcfExample.Server.BL; using RikropWcfExample.Server.Contracts; using System.Threading.Tasks; namespace RikropWcfExample.Server { public class CalculatorService : ICalculatorService { private readonly FibonacciCalculator _fibonacciCalculator; public CalculatorService(FibonacciCalculator.ICtor fibonacciCalculatorCtor) { _fibonacciCalculator = fibonacciCalculatorCtor.Create(); } public async Task<ulong> GetFibonacciNumber(int n) { return await _fibonacciCalculator.Calculate(n); } } }
ä»ã®ãšããã泚æãã¹ãç¹ã®1ã€ã¯ãwcfãµãŒãã¹ãéåæãèšè¿°ããããã«async / awaitã䜿çšããŠããããšã§ãã ãã以å€ã®å Žåãç¹å®ã®ãã¶ã€ã³ã¯ãããŸããã
ããã§ã¯ãç»é²ã«ç§»ããŸãããã ãµãŒããŒã®æãåçŽãªæ§æã¯ããã€ã³ãã£ã³ã°ã®ã¿ã€ãïŒNetTcpïŒã«ãµãŒãã¹ã«è¿œå ããå¿ èŠãããåäœã®ãªã¹ãã瀺ããŸãã
private static IUnityContainer RegisterWcfHosting(this IUnityContainer container, string serviceIp, int servicePort) { container .RegisterServerWcf( o => o.RegisterServiceConnection(reg => reg.NetTcp(serviceIp, servicePort)) .RegisterServiceHostFactory(reg => reg.WithBehaviors().AddDependencyInjectionBehavior()) ); return container; }
ã¯ã©ã€ã¢ã³ãã®å ŽåããµãŒãã¹ã®ã©ãããŒãšã°ãŒãã¥ãŒã¿ãŒã®ã¿ã€ãïŒServiceExecutorïŒããã€ã³ãã£ã³ã°ã®ã©ãããŒã®ã¿ã€ãïŒStandartã¯NetTcpãæ³å®ïŒãå®éã«ã¯ãµãŒããŒã¢ãã¬ã¹ã瀺ãããŸãïŒ
private static IUnityContainer RegisterWcf(this IUnityContainer container, string serviceIp, int servicePort) { container .RegisterClientWcf(o => o.RegisterServiceExecutor(reg => reg.Standard() .WithExceptionConverters() .AddFaultToBusinessConverter()) .RegisterChannelWrapperFactory(reg => reg.Standard()) .RegisterServiceConnection(reg => reg.NetTcp(serviceIp, servicePort))); return container; }
ããã ãã§ã ã€ã³ã¿ãŒãã§ã€ã¹ããšã«åãµãŒãã¹ãç»é²ããå¿ èŠã¯ãããŸããããããã·ãäœæããå¿ èŠããæ§æã«wcfãç»é²ããå¿ èŠããããŸããããããã®ç»é²ã«ãããããããããŒã«ã«ã³ãŒã«ã®ããã«ãµãŒãã¹ã®æäœãããã«éå§ã§ããŸãã
ãã ããæåã«ãµãŒããŒã§ãã¹ãããå¿ èŠããããŸãã Rikrop.Core.Wcfã©ã€ãã©ãªã«ã¯ãã§ã«ServiceHostManagerã¯ã©ã¹ãå«ãŸããŠãããããã¯ãã¹ãŠã®äœæ¥ãç¬èªã«å®è¡ããŸãã åãµãŒãã¹ãç»é²ããå¿ èŠã¯ãããŸããã
using Rikrop.Core.Wcf; using System.Reflection; namespace RikropWcfExample.Server { public class WcfHoster { private readonly ServiceHostManager _serviceHostManager; public WcfHoster(ServiceHostManager serviceHostManager) { _serviceHostManager = serviceHostManager; } public void Start() { var assembly = Assembly.GetExecutingAssembly(); _serviceHostManager.StartServices(assembly); } public void Stop() { _serviceHostManager.StopServices(); } } }
ãµãŒããŒãèµ·åããŸãããïŒ
public static void Main() { using (var serverContainer = new UnityContainer()) { serverContainer.RegisterServerDependencies(); var service = serverContainer.Resolve<WcfHoster>(); service.Start(); Console.WriteLine(" . Enter."); Console.ReadLine(); service.Stop(); } }
ã¯ã©ã€ã¢ã³ããå®è¡ããŸã ã
static void Main() { using (var container = new UnityContainer()) { container.RegisterClientDependencies(); var calculateFibonacciCommandCtor = container.Resolve<CalculateFibonacciCommand.ICtor>(); int number; while (int.TryParse(GetUserInput(), out number)) { var command = calculateFibonacciCommandCtor.Create(); var result = command.Execute(number); Console.WriteLine("Fibonacci[{0}] = {1}", number, result); } } }
åäœããŸãïŒ
åŸæ¥ã®ã¢ãããŒãããã³æ¡åŒµæ§ãšã®æ¯èŒ
ææ¡ããããœãªã¥ãŒã·ã§ã³ã¯ãéåžžã«å€ãã®ã€ã³ãã©ã¹ãã©ã¯ãã£ã³ãŒããå¿ èŠãšããéåžžã®wcfã®äœ¿çšã«æ¯ã¹ãŠå©ç¹ããªãããã«æããããããããŸããã ãããžã§ã¯ãã®äœæ¥äžã«çºçããå žåçãªç¶æ³ã®äŸã«ãã£ãŠéãã瀺ãã®ãæãç°¡åã§ãã
æ¢åã®wcfãµãŒãã¹ãžã®æ°ããã¡ãœããã®è¿œå ããŸãã¯æ¢åã®ã¡ãœããã®çœ²åã®å€æŽ
Rikrop.Core.WcfïŒ.UnityïŒ | ã©ã€ãã©ãªã䜿çšããã« |
---|---|
ããã§ãã¯ã©ã€ã¢ã³ãã§æ°ããã¡ãœãããåŒã³åºãããšãã§ããŸãã |
ããã§ãã¯ã©ã€ã¢ã³ãã§æ°ãããµãŒãã¹ãåŒã³åºãããšãã§ããŸãã |
æ¢åã®ãã¹ãã«æ°ããwcfãµãŒãã¹ãè¿œå ãã
Rikrop.Core.WcfïŒ.UnityïŒ | ã©ã€ãã©ãªã䜿çšããã« |
---|---|
ããã§ãã¯ã©ã€ã¢ã³ãã§æ°ãããµãŒãã¹ãåŒã³åºãããšãã§ããŸãã |
ããã§ãã¯ã©ã€ã¢ã³ãã§æ°ãããµãŒãã¹ãåŒã³åºãããšãã§ããŸãã |
ãã¹ãŠã®wcfãµãŒãã¹ã®èšå®ãå€æŽããïŒäŸãšããŠãã€ã³ãã£ã³ã°ã¿ã€ãã䜿çšïŒ
Rikrop.Core.WcfïŒ.UnityïŒ | ã©ã€ãã©ãªã䜿çšããã« |
---|---|
*ãããªãã¯ã®çµæãåç §ã«ã¹ã¿ã <TServiceConnection>ïŒLifetimeManager lifetimeManager = nullãparams InjectionMember [] injectionMembersïŒããã§ãTServiceConnectionïŒIServiceConnection |
*äœæ¥éã¯wcfãµãŒãã¹ã®æ°ã«æ¯äŸããŸãã ãããã100åããå Žåãè¿ éãªãã¡ã€ã«çœ®æãæ©èœããããšã®ã¿ãæåŸ ã§ããŸãã |
è€æ°ã®wcfãµãŒãã¹ã®èšå®ã®å€æŽïŒãã€ã³ãã£ã³ã°ã¿ã€ããäŸãšããŠäœ¿çšïŒ
Rikrop.Core.WcfïŒ.UnityïŒ | ã©ã€ãã©ãªã䜿çšããã« |
---|---|
|
|
æåŸã®2ã€ã®ãã€ã³ãã«ã€ããŠããã€ãã®èšèãèšã䟡å€ããããŸãã app.configãé©åã«æ§æãããŠããã°ãå€æŽãå ããã®ã¯ãšãŠãç°¡åã§ãã ããã¯ãã¢ããªã±ãŒã·ã§ã³ãåæ§ç¯ããã«å®è¡ã§ããŸãã å®éã®éçºã§ã¯ãwcfæ§é åæ§æã¯éåžžã«ãŸãã§ãããããã¯å埩çãªéçºã«ãããã®ã§ãã ãŸããåæèšå®ãèŠä»¶ãæºãããŠããå Žåãããã°ã©ããŒä»¥å€ã®ãŠãŒã¶ãŒãæ§æãé »ç¹ã«å€æŽããå¿ èŠããããŸãã åæã«ãã³ã³ãã€ã©ãèŠã€ããããªããããªã¿ã€ããã¹ãããããšã¯ç°¡åã§ãã
æ¡åŒµæ§ã ã»ãã·ã§ã³ã®èªå¯ããã³åäœã®åäœ
ç»é²æã®åäœã®è¿œå ã«ãããæ©èœã®æ¡åŒµãšåäœã®å€æŽãçºçããŸãã æãäžè¬çãªã¢ããªã±ãŒã·ã§ã³ã¯ãwcfã¡ãã»ãŒãžã®ããããŒã§ã»ãã·ã§ã³æ å ±ãéä¿¡ããåäœã§ãã
æ©èœã瀺ãããã«ãåã®äŸã®æ¡åŒµã³ãŒãã䜿çšããŠå¥ã®ãã©ã³ããäœæããŸããã æšæºã®åäœèšå®ã§ã¯ãéçºè ã¯æ¿èªæ¹æ³ãéžæããããã«æ±ããããŸã-ããã¯OperationContractã§ããããã¯ãã¡ãã»ãŒãžããããŒã«ã»ãã·ã§ã³ã®ãªããŠãŒã¶ãŒã䜿çšã§ããŸãã ä»ã®ã¡ãœããã®åŒã³åºãã¯ãå ¥åãããããããŒã§ã®ã¿å¯èœã§ãã
ãµãŒããŒã§ã®ç»é²ã¯æ¬¡ã®ããã«ãªããŸãã
container .RegisterType<ISessionResolver<Session>, SessionResolver<Session>>() .RegisterServerWcf( o => o.RegisterServiceConnection(reg => reg.NetTcp(serviceIp, servicePort)) .RegisterServiceHostFactory(reg => reg.WithBehaviors() .AddErrorHandlersBehavior(eReg => eReg.AddBusinessErrorHandler().AddLoggingErrorHandler(NLogger.CreateEventLogTarget())) .AddDependencyInjectionBehavior() .AddServiceAuthorizationBehavior(sReg => sReg.WithStandardAuthorizationManager() .WithStandardSessionHeaderInfo("ExampleNamespace", "SessionId") .WithOperationContextSessionIdInitializer() .WithSessionAuthStrategy<Session>() .WithLoginMethod<ILoginService>(s => s.Login()) .WithOperationContextSessionIdResolver() .WithInMemorySessionRepository() .WithStandardSessionCopier()) ) );
System.ServiceModel.ServiceAuthorizationManagerã®å®è£ ãè¿œå ããããšã§èªèšŒæ¹æ³ãå€æŽã§ããŸããã»ãã·ã§ã³èå¥åã®åæåæ¹æ³ãèªèšŒã®ç¢ºèªæ¹æ³ãã¯ãšãªå®è¡ã®ã³ã³ããã¹ãããã»ãã·ã§ã³ãæœåºããæ¹æ³ããµãŒããŒã«ã»ãã·ã§ã³ãä¿åããã³ã³ããŒããæ¹æ³ãå€æŽããŸãã äžè¬çãªå ŽåãAuthorizationBehaviorã®ç»é²ã¯æ¬¡ã®ããã«ãªããŸãã
.AddServiceAuthorizationBehavior(sReg => sReg.WithCustomAuthorizationManager<ServiceAuthorizationManagerImpl>() .WithCustomSessionHeaderInfo<ISessionHeaderInfoImpl>() .WithCustomSessionIdInitializer<ISessionIdInitializerImpl>() .WithCustomAuthStrategy<IAuthStrategyImpl>() .WithLoginMethod<ILoginService>(s => s.Login()) .WithCustomSessionIdResolver<ISessionIdResolverImpl>() .WithCustomSessionRepository<ISessionRepositoryImpl<MySessionImpl>>() .WithCustomSessionCopier<ISessionCopierImpl<MySessionImpl>>())
ã¯ã©ã€ã¢ã³ãç»é²ãå€æŽãããŸãã
private static IUnityContainer RegisterWcf(this IUnityContainer container, string serviceIp, int servicePort) { container .RegisterType<ClientSession>(new ContainerControlledLifetimeManager()) .RegisterClientWcf(o => o .RegisterServiceExecutor(reg => reg.Standard() .WithExceptionConverters() .AddFaultToBusinessConverter()) .RegisterChannelWrapperFactory(reg => reg.Standard()) .RegisterServiceConnection(reg => reg .NetTcp(serviceIp, servicePort) .WithBehaviors() .AddSessionBehavior(sReg => sReg .WithStandardSessionHeaderInfo("ExampleNamespace", "SessionId") .WithCustomSessionIdResolver<ClientSession>(new ContainerControlledLifetimeManager()) .WithStandardMessageInspectorFactory<ILoginService>(service => service.Login())))); return container; }
çµæïŒ
äœæ¥ã¢ã«ãŽãªãºã
- ã¯ã©ã€ã¢ã³ãã¯ã wcfã³ã³ãã©ã¯ãã§éžæãããã¡ãœãããä»ããŠæ¿èªãããŸãã èªèšŒã«æåãããšããµãŒããŒã¯ã»ãã·ã§ã³ãäœæãããªããžããªã«ä¿åããããã«é¢ããããŒã¿ãã¯ã©ã€ã¢ã³ãã«éä¿¡ããŸãã
var newSession = Session.Create(userId); _sessionRepository.Add(newSession); return new SessionDto { SessionId = newSession.SessionId, Username = "ExampleUserName" };
- ã¯ã©ã€ã¢ã³ãã¯ã»ãã·ã§ã³ããŒã¿ãåä¿¡ããŠââä¿åããŸãã
var clientSession = container.Resolve<ClientSession>(); var sessionDto = Task.Run(async () => await loginServiceExecutor.Execute(s => s.Login())).Result; clientSession.Session = sessionDto;
- ãµãŒããŒã«ã¯ãåŒã³åºãã¯ã©ã€ã¢ã³ãã«é¢ããããŒã¿ãåä¿¡ããæ©èœããããŸãã
public async Task<ulong> GetFibonacciNumber(int n) { var session = _sessionResolver.GetSession(); _logger.LogInfo( string.Format("User with SessionId={0} and UserId={1} called CalculatorService.GetFibonacciNumber", session.SessionId, session.UserId)); return await _fibonacciCalculator.Calculate(n); }
- ã¯ã©ã€ã¢ã³ãã«ã¯ãèš±å¯äžã«ãµãŒããŒããåä¿¡ããããŒã¿ãåä¿¡ããæ©èœããããŸãã
_logger.LogInfo(string.Format("SessionId {0} with name {1} begin calculate Fibomacci", _clientSession.SessionId, _clientSession.Session.Username));
äžèº«ã¯äœã§ãã
ã€ã³ãã©ã¹ãã©ã¯ãã£ã®ã»ãšãã©ã¯ãSystem.ServiceModel.dllã©ã€ãã©ãªã«ãã£ãŠæäŸãããŸãã ãã ãããã詳现ã«æ€èšããå¿ èŠããããœãªã¥ãŒã·ã§ã³ãããã€ããããŸãã
ã¯ã©ã€ã¢ã³ããšãµãŒããŒéã®å¯Ÿè©±ã®åºç€ã¯ãRikrop.Core.Wcfã©ã€ãã©ãªã«ããIServiceExecutorã€ã³ã¿ãŒãã§ã€ã¹ã®å®è£ ã§ãã
public interface IServiceExecutor<out TService> { Task Execute(Func<TService, Task> action); Task<TResult> Execute<TResult>(Func<TService, Task<TResult>> func); }
æãåçŽãªå Žåããã£ãã«ãéãããã®ãã£ãã«ã®ã³ã³ããã¹ãã§ã¡ãœãããåŒã³åºãããŸãã
public async Task<TResult> Execute<TResult>(Func<TService, Task<TResult>> func) { using (var wrapper = _channelWrapperFactory.CreateWrapper()) { return await func(wrapper.Channel); } }
ããè€éãªå®è£ ã§ã¯ããšã©ãŒãå€æããããããããã£ã®å€æŽã«ãã£ãŠåŠçãå®äºãããšãã«éç¥ããããšããããŸãã ãããã®ã¢ã€ãã¢ã¯ãIServiceExecutorã®WPFå®è£ ã§æãåºã䜿çšãããŠããŸããServiceExecutorFactoryã䜿çšãããšãDataBindingã䜿çšããŠUIã«é·ãæäœãéç¥ãããããµãŒããŒããã®å¿çãåŸ æ©ããªããä»»æã®æ å ±ã§ãããã¢ããã衚瀺ãããã§ããwcfãµãŒãã¹ã®ã©ãããŒãäœæã§ããŸãã
å®è£ ãç°¡åã«ããããã«ãäž»ãªåœ¹å²ã¯ãç»é²æã®Fluentã€ã³ã¿ãŒãã§ã€ã¹ãšã©ã€ãã©ãªã€ã³ãã©ã¹ãã©ã¯ãã£ã®æšæºå®è£ ã«ãã£ãŠæããããŸãããã®ãããã¹ã¿ãžãªã®ãã³ãã䜿çšãããšãæãè€éãªæ§é ã§ãåããŠç解ãããããªããŸãã
ä»ã®ã©ã€ãã©ãªãèšäºã§éæ¥çã«èšåãããŠããŸãïŒ
- èªåè»å·¥å Žã®å°å
¥ïŒ
private static IUnityContainer RegisterFactories(this IUnityContainer container) { new[] { Assembly.GetExecutingAssembly(), typeof (FibonacciCalculator).Assembly } .SelectMany(assembly => assembly.DefinedTypes.Where(type => type.Name == "ICtor")) .Where(type => !container.IsRegistered(type)) .ForEach(container.RegisterFactory); return container; }
- ãã¬ãŒã®ã©ãããŒïŒ
private static IUnityContainer RegisterLogger(this IUnityContainer container) { container.RegisterType<ILogger>(new ContainerControlledLifetimeManager(), new InjectionFactory(f => NLogger.CreateConsoleTarget())); return container; }
ãŸãšã
ãããžã§ã¯ãã«ã€ã³ãã©ã¹ãã©ã¯ãã£ãã»ããã¢ããããããIServiceExexutorãä»ãã察話ã®ãããã¯ãŒã¯ã®æ§è³ªãé·ãéå¿ããããšãã§ããŸãã äœç³»çãªã¢ãããŒãã䜿çšããmvvmãã¿ãŒã³ã䜿çšãããã¹ã¯ãããã¢ããªã±ãŒã·ã§ã³ã®æ§ç¯ãããŒã¿ããŒã¹ãšã®å¯Ÿè©± ããã®ã³ã°ãããã³ãã®ä»ã®äžè¬çãªã¿ã¹ã¯ã«ã©ã€ãã©ãªã䜿çšããã®ãæé©ã§ãã ãã ãã銎æã¿ã®ãªããå¿ ããã銎æã¿ã®ãããã¬ãŒã ã¯ãŒã¯ã䜿çšããããªãå Žåã§ãããã®åºã«ãªãã¢ã€ãã¢ãžã®å¿çšãèŠã€ããããšãã§ããŸãã ã³ã³ããŒãã³ãã®æ¡åŒµæ§ãæ§æäžã®å³å¯ãªã¿ã€ãã³ã°ããã¹ãŠã®ã¬ã€ã€ãŒã§ã®å¯Ÿè©±ã®ééæ§ãã€ã³ãã©ã¹ãã©ã¯ãã£ã³ãŒãã®æå°åãããã³ã€ã³ãã©ã¹ãã©ã¯ãã£ã®ã¡ã³ããã³ã¹ã«è²»ããæéã¯ãèšç®æ©ããã³ãã«ããŠãŒã¶ãŒãšã³ã¿ãŒãã©ã€ãºã·ã¹ãã ãäœæããéã«èŠããŠããã¹ãéèŠãªäºé ã§ãã ã©ã€ãã©ãªã䜿çšãã代ããã«ããããžã§ã¯ãã«ãã£ãŠã©ã€ãã©ãªã³ãŒããããŠã³ããŒãããŠãœãªã¥ãŒã·ã§ã³ã«æ¥ç¶ã§ããŸãã ããã«ããããããã¬ãŒã®äžã§äœæ¥ãåŠç¿ããå¿ èŠã«å¿ããŠç¬èªã®å€æŽãå ããããšãã§ããŸãã
ããŒãã¹
ç·Žç¿ã«åããã®ã¯ãããŸããã Rikrop.Core.Wcfã®äœ¿çšã®éçºãšãµããŒãã®éã®ã©ããã®æ®µéã§ãããªã倧ããªãããžã§ã¯ãïŒçŽ300,000è¡ã®ã³ãŒãïŒã翻蚳ããçµéšãããããšãåŠã³ãŸããã ããã¯ã.net 4.0ã®async / awaitã§èŠãã¿ãã»ãã·ã§ã³ã§ã®äœæ¥ãã«ã¹ã¿ãã€ãºããèšå®ããèšå®ãæœåºããããããcïŒãã©ãŒã ã«å€æãããšããããªãèå³æ·±ãçµéšã§ãã ããã誰ã«ãšã£ãŠãèå³æ·±ãå Žåã¯ããã¬ãŒã ã¯ãŒã¯å šäœããã©ãã°ããããšãªãããã®ã©ã€ãã©ãªãžã®ç§»è¡ã®å ·äœäŸã説æã§ããŸãã
ãŸããUIããã¯ãä»ããŠãŠãŒã¶ãŒã«éç¥ããããServiceExecutorFactoryãä»ããŠå®è£ ããããããã¢ããã䜿çšããwpfã®ãœãªã¥ãŒã·ã§ã³ããããŸãã ããã¯ãã©ã€ããŒããªäŸã§ãããwcfãããwpfã«é¢é£ããŠããŸãã ãã ããããã«ãããã©ã€ãã©ãªã®å©ç¹ãšäœ¿çšã®åæ©ã«é¢ãã詳现ãªæ å ±ãåŸãããŸãã