Note that there are some explanatory texts on larger screens.

plurals
  1. PORefactoring "procedural" WCF service
    text
    copied!<p>I'm tryng to refactor a monstrous WCF service into something more manageable. At the time of writing, the service takes about 9 dependencies via constructor, which makes unit testing it very difficult.</p> <p>The service is handling local state via state machine, does validation on the parameters, throws fault exceptions, performs the actual operation and fires publication events via a pub/sub channel. This code is very similar accross all other service calls.</p> <p>I realize that I can do several of those things (argument validation, pub/sub notifications) differently, perhaps via <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming" rel="noreferrer">Aspect-Oriented Programming</a> or WCF behaviors, but my gut tells me that the general approach is wrong -- this feels too "procedural".</p> <p>My goal is to separate the execution of the actual operation from things like pub/sub notifications, and perhaps even error handling.</p> <p>I wonder if acronyms like <a href="http://en.wikipedia.org/wiki/Domain-driven_design" rel="noreferrer">DDD</a> or <a href="http://martinfowler.com/bliki/CQRS.html" rel="noreferrer">CQRS</a> or other techniques can help out here? I am, unfortunately, not very familiar with those concepts beyond the definition.</p> <p>Here's a (simplified) example of one such WCF operation:</p> <pre><code>public void DoSomething(DoSomethingData data) { if (!_stateMachine.CanFire(MyEvents.StartProcessing)) { throw new FaultException(...); } if (!ValidateArgument(data)) { throw new FaultException(...); } var transitionResult = _stateMachine.Fire(MyEvents.StartProcessing); if (!transitionResult.Accepted) { throw new FaultException(...); } try { // does the actual something DoSomethingInternal(data); _publicationChannel.StatusUpdate(new Info { Status = transitionResult.NewState }); } catch (FaultException&lt;MyError&gt; faultException) { if (faultException.Detail.ErrorType == MyErrorTypes.EngineIsOffline) { TryFireEvent(MyServiceEvent.Error, faultException.Detail); } throw; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload