RSCG – Architect.DomainModeling

RSCG – Architect.DomainModeling

name Architect.DomainModeling
author Timo van Zijll Langhout

Domain Modelling -DDD, Entity and more. Here I will show just the builder


This is how you can use Architect.DomainModeling .

The code that you start with is

<Project Sdk="Microsoft.NET.Sdk">



	    <PackageReference Include="Architect.DomainModeling" Version="3.0.2" />



The code that you will use is

using Builder;

var pOld = new Person("Andrei", "Ignat");
pOld.MiddleName = "G";
var build = new PersonBuilder()
    //.WithMiddleName("") // it is not into the constructor
var pNew = build.Build();

namespace Builder;
public class Person
    public Person(string firstName, string lastName)
        FirstName = firstName;
        LastName = lastName;
    public string FirstName { get; set; }
    public string? MiddleName { get; set; }
    public string LastName { get; set; }

    public string FullName()
        return FirstName + " " + MiddleName + " "+LastName;

using Architect.DomainModeling;

namespace Builder;

public partial class PersonBuilder


The code that is generated is

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

#nullable disable

namespace Builder
	/// <summary>
	/// <para>
	/// Implements the Builder pattern to construct <see cref="Builder.Person"/> objects for testing purposes.
	/// </para>
	/// <para>
	/// Where production code relies on the type's constructor, test code can rely on this builder.
	/// That way, if the constructor changes, only the builder needs to be adjusted, rather than lots of test methods.
	/// </para>
	/// </summary>
	/* Generated */ public partial class PersonBuilder
		private string FirstName { get; set; } = "FirstName";
		public PersonBuilder WithFirstName(string value) => this.With(b => b.FirstName = value);

		private string LastName { get; set; } = "LastName";
		public PersonBuilder WithLastName(string value) => this.With(b => b.LastName = value);

		private PersonBuilder With(Action<PersonBuilder> assignment)
			return this;

		public Builder.Person Build()
			var result = new Builder.Person(
				firstName: this.FirstName,
				lastName: this.LastName);
			return result;

Code and pdf at