Skip to content

Instantly share code, notes, and snippets.

View phillippelevidad's full-sized avatar

Phillippe Santana phillippelevidad

View GitHub Profile
@phillippelevidad
phillippelevidad / aggregate-with-root-entity.cs
Last active January 3, 2018 11:03
DDD: aggregate embedding the root entity's properties or with a reference to root entity?
// Aggregate has a reference to its root entity.
public class WebAppAggregate : Aggregate
{
public Guid Id; // Aggregate Id.
public WebAppEntity WebApp;
public WebAppAggregate(Guid id, WebAppEntity webApp);
public Result SomeInvariant(...);
}
@phillippelevidad
phillippelevidad / WebAppAggregate.cs
Last active January 3, 2018 11:50
Solution attempt for the Web Monitoring domain modeling.
/* File structure:
* /Domain/WebMonitoring/WebAppAggregate/WebApp.cs
* /Domain/WebMonitoring/WebAppAggregate/WebAppService.cs
* /Domain/WebMonitoring/WebAppAggregate/IWebAppRepository.cs
* /Domain/WebMonitoring/WebAppAggregate/IHttpStatusChecker.cs
*
* This way, the Aggregate itself is not "materialized" as a class or any programming resource.
* It is a concept, and its invariants are enforced by the WebApp (entity, aggregate root) and
* WebAppService.
*/
@phillippelevidad
phillippelevidad / Guard.cs
Created January 22, 2018 17:19
Guard for easily implementing parameter validation in C#
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Net.Mail;
using System.Text.RegularExpressions;
namespace Domain.Core
{
public interface IGuardClause { }
/*!
Double Click Scroller
license: MIT
https://gist.github.com/phillippelevidad/7e5723ec2a69347b1dd65a378f66de8b
JavaScript funcionality similar to Basecamp's: double click the first third of the viewport to smoothly scroll to the top,
and the bottom third to scroll to the bottom. Quick up and down page navigation!
JQuery is required.
Just call dblclickScroller.init() and you're done.
@phillippelevidad
phillippelevidad / self-signed-certificate-https.ps1
Created October 8, 2018 12:52
Generate a self-signed certificate on Windows
# Generate a self-signed certificate
# Browse to Control Panel > Manage computer certificates > Personal > Certificates and find yours
$dnsName = "www.example.com"
$friendlyName = "Example"
New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName $dnsName -FriendlyName $friendlyName -NotAfter (Get-Date).AddYears(10)
@phillippelevidad
phillippelevidad / UserVoiceDddDomain.cs
Last active October 19, 2018 17:25
User Voice DDD - domain implementation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace UserVoiceFun.Domain
{
public abstract class Entity
{
public Guid Id { get; protected set; } = Guid.NewGuid();
@phillippelevidad
phillippelevidad / EfCoreSoftDelete.cs
Last active October 19, 2018 14:56
EF Core 2 implementation of SoftDeletes
/*
* EF Core implementation of SoftDeletes.
*
* Just specify entity types that should not be hard deleted in the SoftDeleteMapper class
* and this code will handle the rest, by:
* 1. Adding the IsDeleted and DeletedAt columns;
* 2. Applying a query filter to prevent soft-deleted entries from being returned on reads;
* 3. Automatically rewriting deletes so that they only set entries as deleted, preventing hard-deletes.
*/
@phillippelevidad
phillippelevidad / add-remove-has-class.js
Created February 12, 2019 19:45
Pure-javascript functions to add/remove CSS classes.
// Adapted from https://stackoverflow.com/a/28344281/484108
// and https://jaketrent.com/post/addremove-classes-raw-javascript/
function hasClass(el, className) {
return !!el.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'));
}
function addClass(el, className) {
if (!hasClass(el, className)) el.className += ' ' + className;
}
@phillippelevidad
phillippelevidad / InjectionFixture.cs
Created March 27, 2019 20:11
xUnit: add Startup to test project and reuse configurations
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using System;
using System.Net.Http;
namespace Tests
{
public class InjectionFixture : IDisposable
{
private readonly TestServer server;
public class Customer : Entity
{
public Guid Id { get; set; }
public string Name { get; set; }
public bool IsAdvanced { get; set; }
}