I've an HttpHandler, which allows users to login to a system by passing in an encrypted code.
ProcessRequest it performs quite a few steps.
- Retrieve the encrypted code from request (could be in Form/X-Header/Query)
- Decrypt it. (Results in an JSON string)
- Deserialize to a dynamic type
- Determine the type of request, could be login/register/activate
- Validate request
- Load user subscription
- Load User entity
- If Req.Type = Login -> Login using FormsAuth
- If Req.Type = Register -> Create user
- If Req.Type = Register -> Send Activation email
This goes on. Currently this is something like a long if/else statement which I'm trying to refactor. I'm thinking of using the Chain Of Responsibility pattern to convert these steps in if/else to a chain which executes sequentially. However, this will be different from original CoR as only last few steps will actually "handle" the request, first steps will just do some pre-processing and make stage for last steps to perform it's job.
My main problem is, different steps in the chain will work on different input data. First few steps (Decryption, Deserialization, etc) will work on strings while latter half should ideally work on deserialized dynamic object. I don't like the way it sounds.
Am I trying to fit a round lid to an square bottle? Is this not a scenario where CoR can/should be applied? Are there any other patterns/strategies I could use to solve such scenarios.
I thought of using the decorator pattern as well, but that doesn't suite me very well, as I'd like to be able to switch certain steps in and out (ex: email activation) for some scenarios.
NOTE: I've seen this question as well, but not sure if it answers my question.