Skip to content

Instantly share code, notes, and snippets.

View NMillard's full-sized avatar
🏠
Working from home

Nicklas Millard NMillard

🏠
Working from home
View GitHub Profile
@NMillard
NMillard / buisness-logic-and-rules.md
Last active May 30, 2018 14:14
Business logic and rules

Business logic and rules

The conceptual distinction between business logic and rules is important for understanding how to solve a problem through code.

Business logic

This may be thought of as the reasoning of how to solve something, that is unique to the business domain.

Business rules

Rules are ideally contraints that a subject, procedure, or algorithm has to adhere to. Business rules are unique to the business as well, and are often refered to as policies.

@NMillard
NMillard / ProficiencyLevel.cs
Last active August 17, 2019 08:54
Language Proficiency Rules Example
namespace LearnReflection.RulesEngine.Rules {
public enum ProficiencyLevel {
Unknown,
Beginner,
Intermediate,
Proficient
}
}
namespace LearnReflection.RulesEngine.Rules {
@NMillard
NMillard / IProficiencyRule.cs
Created August 17, 2019 08:54
Language Proficiency Interface Example
namespace LearnReflection.RulesEngine.Rules {
public interface IProficiencyRule {
ProficiencyLevel CheckProficiency(int[] results);
}
}
@NMillard
NMillard / ProficiencyChecker.cs
Last active August 17, 2019 08:58
Language Proficiency Rules Checker Example
namespace LearnReflection.RulesEngine {
public class ProficiencyChecker {
private readonly IEnumerable<IProficiencyRule> _rules;
public ProficiencyChecker() {
_rules = LoadRules();
}
public ProficiencyLevel EvaluateProficiencyLevel(int[] studentResults) {
IEnumerable<ProficiencyLevel> evaluationResults = _rules
@NMillard
NMillard / IntermediateRule.cs
Created August 17, 2019 09:09
Intermediate rule
namespace LearnReflection.RulesEngine.Rules {
public class IntermediateRule : IProficiencyRule {
public ProficiencyLevel CheckProficiency(int[] results) => results.Sum() < 3
? ProficiencyLevel.Beginner
: ProficiencyLevel.Unknown;
}
}
@NMillard
NMillard / ApplicationContext.cs
Last active January 18, 2020 15:34
EntityFramework examples
using EFPractice.DataLayer.Interfaces;
using EFPractice.Domain;
using Microsoft.EntityFrameworkCore;
namespace EFPractice.DataLayer {
internal class ApplicationContext : DbContext, IDataStore {
public ApplicationContext(DbContextOptions options) : base(options) {}
public DbSet<Author> Authors { get; set; }
public DbSet<Book> Books { get; set; }
@NMillard
NMillard / Startup.cs
Last active November 13, 2020 20:02
Configuring Startup to use JWT authorization
// ... imports
namespace Authentication.WebClient {
public class Startup {
private readonly IConfiguration configuration;
public Startup(IConfiguration configuration) {
this.configuration = configuration;
}
@NMillard
NMillard / AuthorizationController.cs
Last active March 24, 2020 12:44
Generate and validate JWT
// ... imports
namespace Authentication.WebClient.Controllers {
[ApiController]
[Route("api/[controller]/[action]")]
public class AuthorizationController : ControllerBase {
private readonly IConfiguration configuration;
public AuthorizationController(IConfiguration configuration) {
@NMillard
NMillard / appsettings.json
Created March 24, 2020 13:01
Appsettings for JWT example
{
"Jwt": {
"Symmetric": {
"Key": ""
},
"Asymmetric": {
"PrivateKey": "",
"PublicKey": "MIIBCgKCAQEAsXoUruE3QybI3ygaARBUl0e663kxvylbSqlLBPf/lONUpWNucph5RQK/9WepNS/Z42Y79x+jf6MyPkgpMoLiiYB6Nzm5ssmZHg0ImzLmdyc3enCA0/TNrX8QBqieeLmm4Qja2pgsqtX7ae4En2Mr38qLrrpiMOXRqtxgVYqi+Lv9UxfVkRwHB4C+wc9FkM0IhmCja+AvpvtG7UBskPYLRB8o9gELVggKpV9t48yIEtJXG97BzmH3anEYZJY611NylZ1VUbnFbmRGJjAqF6Gy4bcGJbJrRlEQSGZT7mKKlxEijBR1VjADaQc8YVQXI76q1B3NiBcfvPSOJ+MSszd36QIDAQAB"
}
},
@NMillard
NMillard / GenerateKeys.cs
Last active August 4, 2022 09:17
Create RSA key paris
class Program {
static void Main(string[] args) {
using RSA rsa = RSA.Create();
Console.WriteLine($"-----Private key-----{Environment.NewLine}{Convert.ToBase64String(rsa.ExportRSAPrivateKey())}{Environment.NewLine}");
Console.WriteLine($"-----Public key-----{Environment.NewLine}{Convert.ToBase64String(rsa.ExportRSAPublicKey())}");
}
}