0

I was reading up on how to clean up post functions and the idea seems very useful. I added onto the idea of an IFormHandler by adding a couple more methods and making the class abstract.

public abstract class FormHandler<T>
{
    private readonly UnitOfWork unit;

    public FormHandler(UnitOfWork unit)
    {
        this.unit = unit;
    }

    protected UnitOfWork Unit
    {
        get
        {
            return this.unit;
        }
    }

    public virtual void PreValidation(ModelStateDictionary modelState, T form)
    {

    }

    public abstract void Handle(T form);

    public virtual void OnValidationFailure(T form)
    {

    }
}

This works excellent for post functions and my controllers are alot lighter and easier to understand. I wanted to clean up the GET functions as well. Has anyone already attempted this or have any ideas of how to make the GET functions cleaner?

Stefan Bossbaly
  • 6,682
  • 9
  • 53
  • 82

1 Answers1

1

I like the IQueryProcessor pattern mentioned here. Steven also has a good article on implementing an ICommandHandler interface, similar to what you've done, though with dependency injection rather than an abstract class with inherited methods.

Steven
  • 166,672
  • 24
  • 332
  • 435
danludwig
  • 46,965
  • 25
  • 159
  • 237