Skip to content

Instantly share code, notes, and snippets.

@hmemcpy
Created February 12, 2013 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmemcpy/4761279 to your computer and use it in GitHub Desktop.
Save hmemcpy/4761279 to your computer and use it in GitHub Desktop.
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.
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.
I realize that I can do several of those things (argument validation, pub/sub notifications) differently, perhaps via WCF behaviors, but my gut tells me that the general approach is wrong -- this feels too "procedural".
I wonder if acronyms like DDD or CQRS or other techniques can help out here?
Thanks!
Here's a (simplified) example of one such WCF operation:
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)
{
OnFinished(command);
throw new FaultException(...);
}
try
{
DoSomethingInternal(data); // does the actual something
_publicationChannel.StatusUpdate(new Info { Status = transitionResult.NewState });
}
catch (FaultException<MyError> faultException)
{
if (faultException.Detail.ErrorType == MeasurementManagerErrorType.EngineIsDown)
{
TryFireEvent(MyServiceEvent.Error, faultException.Detail);
}
throw;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment