Skip to content

Instantly share code, notes, and snippets.

@schotime
Forked from jmarnold/IModelTypeCoordinator.cs
Created July 29, 2011 06:15
Show Gist options
  • Save schotime/1113267 to your computer and use it in GitHub Desktop.
Save schotime/1113267 to your computer and use it in GitHub Desktop.
ValidationBehavior<T>
public class ValidationBehavior<T> : BasicBehavior where T : class
{
IFubuRequest request;
IChainResolver chain;
IPartialFactory _factory;
public ValidationBehavior(IFubuRequest request, IChainResolver chain, IPartialFactory factory) : base(PartialBehavior.Executes)
{
this.request = request;
this.chain = chain;
this._factory = factory;
}
protected override DoNext performInvoke()
{
var model = request.Get<T>();
var achain = chain.FindUniqueByInputType(typeof(T));
var getchain = chain.Find(achain.FirstCall().HandlerType, achain.FirstCall().HandlerType.GetMethod("Get"));
var input = Activator.CreateInstance(getchain.FirstCall().InputType());
var errorType = input as ErrorModel;
errorType.Error = "Error Bitch";
request.Set(input);
factory.BuildPartial(getchain.FirstCall()).InvokePartial();
return DoNext.Stop;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment