// ReSharper disable UnusedMember.Local internal void ServiceCommandMethodGeneric <TCommand>( MethodInfo concreteMethodInfo, CommandOperationAttribute commandAttribute) // ReSharper restore UnusedMember.Local { var commandEndpointDetails = _endpointDetailsProvider .GetEndpointDetails(commandAttribute.CommandEndpointKey); var execute = (Func <TCommand, IObservable <Unit> >)Delegate.CreateDelegate( typeof(Func <TCommand, IObservable <Unit> >), this, concreteMethodInfo, true); var subscription = _commandListener .GetCommandStream <TCommand>(commandEndpointDetails) .Subscribe(command => { RequestContext.Current = new RequestContext(command.SenderSessionId); try { execute(command.Command); } catch (Exception) { throw new NotImplementedException(); } finally { RequestContext.Current = null; } }); _subscriptions.Add(subscription); }
private void ServiceCommandMethod( Type commandType, MethodInfo concreteMethodInfo, CommandOperationAttribute commandAttribute) { var thisType = GetType(); var openMethodInfo = thisType.GetMethod("ServiceCommandMethodGeneric", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod); var typeArguments = new[] { commandType }; var closedMethodInfo = openMethodInfo.MakeGenericMethod(typeArguments); var parameters = new object[] { concreteMethodInfo, commandAttribute }; closedMethodInfo.Invoke(this, parameters); }