Skip to content

Instantly share code, notes, and snippets.

View thangchung's full-sized avatar
:electron:
Sharing is caring

Thang Chung thangchung

:electron:
Sharing is caring
View GitHub Profile
#!/bin/bash
PROTOC_REPO="google/protobuf"
# Credits to: lukechilds here: https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
get_latest_release() {
URL="https://api.github.com/repos/$1/releases/latest"
VERSION=$(curl --silent $URL |grep '"tag_name":' |sed -E 's/.*"([^"]+)".*/\1/')
echo $VERSION
}
@thangchung
thangchung / cart-db-dep.yaml
Last active September 7, 2018 04:06
Clean Domain-driven Design article - Kubernetes manifests
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: cartdb-v1
namespace: {{ .Release.Namespace }}
spec:
replicas: 1
template:
metadata:
labels:
@thangchung
thangchung / Dockerfile
Created September 7, 2018 04:04
Clean Domain-driven Design article - Cart Dockerfile
FROM microsoft/dotnet:2.1.2-aspnetcore-runtime-alpine AS base
WORKDIR /app
ARG service_version
ENV SERVICE_VERSION ${service_version:-0.0.1}
ARG api_version
ENV API_VERSION ${api_version:-1.0}
ENV ASPNETCORE_URLS http://+:5003
@thangchung
thangchung / CartController.cs
Created September 7, 2018 04:03
Clean Domain-driven Design article - CartController.cs
[ApiController]
[ApiVersion("1.0")]
[Route("api/carts")]
public class CartController : Controller
{
[HttpGet]
[Route("{id}")]
[Auth(Policy = "access_cart_api")]
public async Task<IActionResult> Get([FromServices] IMediator eventor, Guid id, CancellationToken cancellationToken)
{
@thangchung
thangchung / RequestHandler.cs
Created September 7, 2018 04:01
Clean Domain-driven Design article - Checkout
public class RequestHandler : TxRequestHandlerBase<CheckoutRequest, CheckoutResponse>
{
public RequestHandler(IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf)
: base(uow, qrf)
{
}
public override async Task<CheckoutResponse> Handle(CheckoutRequest request, CancellationToken cancellationToken)
{
var cartCommander = UnitOfWork.Repository<Domain.Cart>();
@thangchung
thangchung / RequestHandler.cs
Created September 7, 2018 03:58
Clean Domain-driven Design article - Delete Product in the Cart
public class RequestHandler : TxRequestHandlerBase<DeleteItemRequest, DeleteItemResponse>
{
private readonly ICatalogGateway _catalogGateway;
private readonly IShippingGateway _shippingGateway;
private readonly IPromoGateway _promoGateway;
public RequestHandler(IUnitOfWorkAsync uow, IQueryRepositoryFactory qf,
ICatalogGateway cgw, IShippingGateway shippingGateway, IPromoGateway promoGateway)
: base(uow, qf)
{
@thangchung
thangchung / RequestHandler.cs
Created September 7, 2018 03:56
Clean Domain-driven Design article - Update Product in the Cart
public class RequestHandler : TxRequestHandlerBase<UpdateItemInCartRequest, UpdateItemInCartResponse>
{
private readonly ICatalogGateway _catalogGateway;
private readonly IShippingGateway _shippingGateway;
private readonly IPromoGateway _promoGateway;
public RequestHandler(IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf,
ICatalogGateway catalogGateway, IShippingGateway shippingGateway,
IPromoGateway promoGateway) : base(uow, qrf)
{
@thangchung
thangchung / RequestHandler.cs
Created September 7, 2018 03:54
Clean Domain-driven Design article - Add Product to a Cart
public class RequestHandler : TxRequestHandlerBase<InsertItemToNewCartRequest, InsertItemToNewCartResponse>
{
private readonly ICatalogGateway _catalogGateway;
private readonly IShippingGateway _shippingGateway;
private readonly IPromoGateway _promoGateway;
public RequestHandler(
IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf,
ICatalogGateway catalogGateway, IShippingGateway shippingGateway,
IPromoGateway promoGateway) : base(uow, qrf)
@thangchung
thangchung / RequestHandler.cs
Created September 7, 2018 03:52
Clean Domain-driven Design article - Get Cart with Products
public class RequestHandler : RequestHandlerBase<GetCartRequest, GetCartResponse>
{
private readonly ICatalogGateway _catalogGateway;
private readonly IShippingGateway _shippingGateway;
private readonly IPromoGateway _promoGateway;
public RequestHandler(ICatalogGateway cgw, IQueryRepositoryFactory qrf,
IShippingGateway shippingGateway, IPromoGateway promoGateway)
: base(qrf)
{
@thangchung
thangchung / Product.cs
Created September 7, 2018 03:48
Clean Domain-driven Design article
public sealed class Product : IdentityBase
{
private Product() : base()
{
}
private Product(Guid productId)
: this(productId, string.Empty, 0.0D, string.Empty)
{
}