0

I'm new here and a beginner architect. I'm helping the company I work to design our new product and since I start it, I read a lot about but is never enough.

I decided to use Mediator Pattern (with Mediatr) to call my application layer. It's cool and I got how to work with it sometimes, but sometimes I get confused.

For example, when we publish a document on our new product, we uses a RequestHandler to do everything and check all rules it needs, it's fine and works like a charm, but, when I want just a quick data, it looks likes too much for just a simple thing.

As an example, every time the user do any kind of action on my web application, I have to check if he is still logged. We have single login per user, so, if the same user connect anywhere else, the older session expires. We do it by saving on database.

On every action of my app, I go to base and check if the session key is the same, as bellow.

var sessionKey = bibliotecaCookie.Value;
var mediator = controller.GetMediator();
var isUserSessionKeyValidRequest = new IsUserSessionKeyValidRequest() 
{
    sessionKey = sessionKey
};
var isValidSession = mediator.Send(isUserSessionKeyValidRequest).Result;
if (!isValidSession)
    throw new UnauthorizedAccessException();

So, I have a RequestHandler (a Handler and a Request which returns a bool) just to check if the user session is ok.

When the handler catches this request, it goes to database and execute a simple rule which is "Is the passed session the same as the stored session key?".

Is it right? Is it the right approach? Did I understand it right?

Thanks in advance guys

3
  • .Result on the end? use async/await!
    – Alex
    Aug 6, 2019 at 22:04
  • 1
    Your understanding of the mediator pattern is ok (handler handles the request, returns a bool) - your auth model sounds a bit of a mess though, but that's off topic for this question
    – Alex
    Aug 6, 2019 at 22:06
  • @Alex I have to keep an integration with a legacy system, maybe (or not) it looks like a mess, but its just a prototype. Aug 7, 2019 at 14:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.