Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Interface;
using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Model;

namespace Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Abstraction
{
public abstract class RequestHandler : IRequestHandler
{
private IRequestHandler _nextHandler;

public void SetNextHandler(IRequestHandler handler)
{
_nextHandler = handler;
}

public void HandleRequest(Request request)
{
ProcessRequest(request);

if (_nextHandler != null)
{
_nextHandler.HandleRequest(request);
}
}

protected abstract void ProcessRequest(Request request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Model;

namespace Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Interface
{
public interface IRequestHandler
{
void SetNextHandler(IRequestHandler handler);
void HandleRequest(Request request);
}
}
16 changes: 16 additions & 0 deletions Behavioral/ChainOfResponsibility/RuleEngine/Model/Request.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Model
{
public class Request
{
public string Username { get; set; }
public string Password { get; set; }

// Other properties
}
}
28 changes: 26 additions & 2 deletions Behavioral/ChainOfResponsibility/RuleEngine/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Model;
using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Providers;


// Create the request handlers
var validationHandler = new ValidationHandler();
var authenticationHandler = new AuthenticationHandler();
var authorizationHandler = new AuthorizationHandler();



// Set the chain of responsibility
validationHandler.SetNextHandler(authenticationHandler);
authenticationHandler.SetNextHandler(authorizationHandler);


// Create a request
var request = new Request { Username = "hwpro" , Password = "123"};


// Process the request
validationHandler.HandleRequest(request);


Console.ReadLine();
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Abstraction;
using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Model;

namespace Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Providers
{
public class AuthenticationHandler : RequestHandler
{
protected override void ProcessRequest(Request request)
{
Console.WriteLine("Authentication handler processing request");
// Perform authentication logic
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Abstraction;
using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Model;

namespace Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Providers
{
public class AuthorizationHandler : RequestHandler
{
protected override void ProcessRequest(Request request)
{
Console.WriteLine("Authorization handler processing request");
// Perform authorization logic
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Abstraction;
using Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Model;

namespace Thisisnabi.DesignPattern.Behavioral.ChainOfResponsibility.RuleEngine.Providers
{
public class ValidationHandler : RequestHandler
{
protected override void ProcessRequest(Request request)
{
Console.WriteLine("Validation handler processing request");
// Perform validation logic
}
}
}