{"id":13629494,"url":"https://github.com/SzymonHalucha/Minerals.AutoDomain","last_synced_at":"2025-04-17T09:34:16.244Z","repository":{"id":239595039,"uuid":"799630056","full_name":"SzymonHalucha/Minerals.AutoDomain","owner":"SzymonHalucha","description":"Simple package that supports the creation of aggregates and entities for the domain layer using an incremental source generator","archived":false,"fork":false,"pushed_at":"2024-05-25T06:54:22.000Z","size":111,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-20T11:13:10.993Z","etag":null,"topics":["csharp","csharp-sourcegenerator","ddd","ddd-patterns","domain-driven-design","dotnet","roslyn"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SzymonHalucha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-12T17:53:12.000Z","updated_at":"2024-08-01T22:36:47.226Z","dependencies_parsed_at":"2024-05-19T10:24:16.263Z","dependency_job_id":"8d075803-ead4-4fd2-ad2c-a4b805c93467","html_url":"https://github.com/SzymonHalucha/Minerals.AutoDomain","commit_stats":null,"previous_names":["szymonhalucha/minerals.autodomain"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SzymonHalucha%2FMinerals.AutoDomain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SzymonHalucha%2FMinerals.AutoDomain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SzymonHalucha%2FMinerals.AutoDomain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SzymonHalucha%2FMinerals.AutoDomain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SzymonHalucha","download_url":"https://codeload.github.com/SzymonHalucha/Minerals.AutoDomain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223751171,"owners_count":17196583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csharp-sourcegenerator","ddd","ddd-patterns","domain-driven-design","dotnet","roslyn"],"created_at":"2024-08-01T22:01:12.065Z","updated_at":"2024-11-08T20:31:03.085Z","avatar_url":"https://github.com/SzymonHalucha.png","language":"C#","readme":"# Minerals.AutoDomain\n\n![GitHub License](https://img.shields.io/github/license/SzymonHalucha/Minerals.AutoDomain?style=for-the-badge)\n![NuGet Version](https://img.shields.io/nuget/v/Minerals.AutoDomain?style=for-the-badge)\n![NuGet Downloads](https://img.shields.io/nuget/dt/Minerals.AutoDomain?style=for-the-badge)\n\n[Package on nuget.org](https://www.nuget.org/packages/Minerals.AutoDomain/)\n\n*WORK IN PROGRESS...*\n\nThis package, with the help of an incremental source generator, provides a fast method of defining domain layer components with their specific implementation, such as aggregates, entities and domain events.\n\n## Features\n\n- **Reduced boilerplate:** Spend less time writing boilerplate code and more time crafting the business logic of your application.\n- **Strongly typed identifier:** Package has integrated automatic generation of strongly typed identifiers for every entity and aggregate.\n- **Domain events:** Package gives you the ability to customize arguments for automatically generated domain events.\n- **Compatible with .NET Standard 2.0 and C# 7.3+:** Works on a wide range of platforms and development environments.\n\n## Installation\n\nAdd the Minerals.AutoDomain nuget package to your C# project using the following methods:\n\n### 1. Project file definition\n\n```xml\n\u003cPackageReference Include=\"Minerals.AutoDomain\" Version=\"0.4.0\" /\u003e\n```\n\n### 2. dotnet command\n\n```bat\ndotnet add package Minerals.AutoDomain\n```\n\n## Usage\n\nPackage is used by adding the selected attribute to the suitable object.\n\n### Entity\n\nSample code fragment that is needed to generate Entity, please notice that the class that implements the Entity attribute for correct functioning should have a ``partial`` modifier.\n\n```csharp\n// ...\n[Minerals.AutoDomain.Entity]\npublic partial class ExampleEntity\n{\n    // Your code here...\n}\n// ...\n```\n\nThe code above will generate a two files with the following code:\n\n```csharp\n// \u003cauto-generated\u003e\n// This code was generated by a tool.\n// Name: Minerals.AutoDomain.Generators\n// Version: {Version}\n// \u003c/auto-generated\u003e\n[global::System.Diagnostics.DebuggerNonUserCode]\n[global::System.Runtime.CompilerServices.CompilerGenerated]\n[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\npublic partial class ExampleEntity : global::Minerals.AutoDomain.IEntity, global::System.IEquatable\u003cExampleEntity\u003e\n{\n    public ExampleEntityId Id { get; private set; }\n\n    public bool Equals(ExampleEntity other)\n    {\n        return other.Id.Value.Equals(Id.Value);\n    }\n\n    public override bool Equals(object obj)\n    {\n        return obj is ExampleEntity other \u0026\u0026 other.Id.Value.Equals(Id.Value);\n    }\n\n    public override int GetHashCode()\n    {\n        return Id.Value.GetHashCode();\n    }\n\n    public static bool operator ==(ExampleEntity left, ExampleEntity right)\n    {\n        return left != null \u0026\u0026 right != null \u0026\u0026 left.Id.Value.Equals(right.Id.Value);\n    }\n\n    public static bool operator !=(ExampleEntity left, ExampleEntity right)\n    {\n        return (left != null \u0026\u0026 right == null) || (left == null \u0026\u0026 right != null) || !left.Id.Value.Equals(right.Id.Value);\n    }\n}\n\n// And\n\n// \u003cauto-generated\u003e\n// This code was generated by a tool.\n// Name: Minerals.AutoDomain.Generators\n// Version: {Version}\n// \u003c/auto-generated\u003e\n[global::System.Diagnostics.DebuggerNonUserCode]\n[global::System.Runtime.CompilerServices.CompilerGenerated]\n[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\npublic readonly struct ExampleEntityId : global::System.IEquatable\u003cExampleEntityId\u003e\n{\n    public int Value =\u003e _value;\n\n    private readonly int _value;\n\n    public ExampleEntityId(int value)\n    {\n        _value = value;\n    }\n\n    public bool Equals(ExampleEntityId other)\n    {\n        return other.Value.Equals(Value);\n    }\n\n    public override bool Equals(object obj)\n    {\n        return obj is ExampleEntityId other \u0026\u0026 other.Value.Equals(Value);\n    }\n\n    public override int GetHashCode()\n    {\n        return Value.GetHashCode();\n    }\n\n    public static bool operator ==(ExampleEntityId left, ExampleEntityId right)\n    {\n        return left.Value.Equals(right.Value);\n    }\n\n    public static bool operator !=(ExampleEntityId left, ExampleEntityId right)\n    {\n        return !left.Value.Equals(right.Value);\n    }\n}\n```\n\n### AggregateRoot\n\nSample code fragment that is needed to generate AggregateRoot, please notice that the class that implements the AggregateRoot attribute for correct functioning should have a ``partial`` modifier.\n\n```csharp\n// ...\n[Minerals.AutoDomain.AggregateRoot]\npublic partial class ExampleAggregateRoot\n{\n    // Your code here...\n}\n// ...\n```\n\nThe code above will generate a two files with the following code:\n\n```csharp\n// \u003cauto-generated\u003e\n// This code was generated by a tool.\n// Name: Minerals.AutoDomain.Generators\n// Version: {Version}\n// \u003c/auto-generated\u003e\n[global::System.Diagnostics.DebuggerNonUserCode]\n[global::System.Runtime.CompilerServices.CompilerGenerated]\n[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\npublic partial class ExampleAggregate : global::Minerals.AutoDomain.IAggregateRoot, global::System.IEquatable\u003cExampleAggregate\u003e\n{\n    public ExampleAggregateId Id { get; private set; }\n\n    public global::System.Collections.Generic.IReadOnlyCollection\u003cglobal::Minerals.AutoDomain.IDomainEvent\u003e DomainEvents =\u003e _domainEvents.AsReadOnly();\n\n    private readonly global::System.Collections.Generic.List\u003cglobal::Minerals.AutoDomain.IDomainEvent\u003e _domainEvents = new global::System.Collections.Generic.List\u003cglobal::Minerals.AutoDomain.IDomainEvent\u003e();\n\n    public void AppendDomainEvent(global::Minerals.AutoDomain.IDomainEvent domainEvent)\n    {\n        _domainEvents.Add(domainEvent);\n    }\n\n    public void ClearDomainEvents()\n    {\n        _domainEvents.Clear();\n    }\n\n    public bool Equals(ExampleAggregate other)\n    {\n        return other.Id.Value.Equals(Id.Value);\n    }\n\n    public override bool Equals(object obj)\n    {\n        return obj is ExampleAggregate other \u0026\u0026 other.Id.Value.Equals(Id.Value);\n    }\n\n    public override int GetHashCode()\n    {\n        return Id.Value.GetHashCode();\n    }\n\n    public static bool operator ==(ExampleAggregate left, ExampleAggregate right)\n    {\n        return left != null \u0026\u0026 right != null \u0026\u0026 left.Id.Value.Equals(right.Id.Value);\n    }\n\n    public static bool operator !=(ExampleAggregate left, ExampleAggregate right)\n    {\n        return (left != null \u0026\u0026 right == null) || (left == null \u0026\u0026 right != null) || !left.Id.Value.Equals(right.Id.Value);\n    }\n}\n\n// And\n\n// \u003cauto-generated\u003e\n// This code was generated by a tool.\n// Name: Minerals.AutoDomain.Generators\n// Version: {Version}\n// \u003c/auto-generated\u003e\n[global::System.Diagnostics.DebuggerNonUserCode]\n[global::System.Runtime.CompilerServices.CompilerGenerated]\n[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\npublic readonly struct ExampleAggregateId : global::System.IEquatable\u003cExampleAggregateId\u003e\n{\n    public int Value =\u003e _value;\n\n    private readonly int _value;\n\n    public ExampleAggregateId(int value)\n    {\n        _value = value;\n    }\n\n    public bool Equals(ExampleAggregateId other)\n    {\n        return other.Value.Equals(Value);\n    }\n\n    public override bool Equals(object obj)\n    {\n        return obj is ExampleAggregateId other \u0026\u0026 other.Value.Equals(Value);\n    }\n\n    public override int GetHashCode()\n    {\n        return Value.GetHashCode();\n    }\n\n    public static bool operator ==(ExampleAggregateId left, ExampleAggregateId right)\n    {\n        return left.Value.Equals(right.Value);\n    }\n\n    public static bool operator !=(ExampleAggregateId left, ExampleAggregateId right)\n    {\n        return !left.Value.Equals(right.Value);\n    }\n}\n```\n\n### Domain Events\n\nThe code below will generate a partial struct with comparison methods.\n\n```csharp\n[Minerals.AutoDomain.DomainEvent]\npublic readonly partial struct ExampleDomainEvent\n{\n    public string Property1 { get; }\n    public readonly int Field1;\n}\n```\n\nThe code fragment shown above will generate the following domain events code, please notice that the generated events are in the ``Events`` sub-namespace.\n\n```csharp\n// \u003cauto-generated\u003e\n// This code was generated by a tool.\n// Name: Minerals.AutoDomain.Generators\n// Version: {Version}\n// \u003c/auto-generated\u003e\n[global::System.Diagnostics.DebuggerNonUserCode]\n[global::System.Runtime.CompilerServices.CompilerGenerated]\n[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\npublic readonly partial struct ExampleDomainEvent : global::Minerals.AutoDomain.IDomainEvent, global::System.IEquatable\u003cExampleDomainEvent\u003e\n{\n    public bool Equals(ExampleDomainEvent other)\n    {\n        return other.Field1.Equals(Field1) \u0026\u0026 other.Property1.Equals(Property1);\n    }\n\n    public override bool Equals(object obj)\n    {\n        return obj is ExampleDomainEvent other \u0026\u0026 other.Field1.Equals(Field1) \u0026\u0026 other.Property1.Equals(Property1);\n    }\n\n    public override int GetHashCode()\n    {\n        return global::System.HashCode.Combine(Field1, Property1);\n    }\n\n    public static bool operator ==(ExampleDomainEvent left, ExampleDomainEvent right)\n    {\n        return left.Field1.Equals(right.Field1) \u0026\u0026 left.Property1.Equals(right.Property1);\n    }\n\n    public static bool operator !=(ExampleDomainEvent left, ExampleDomainEvent right)\n    {\n        return !left.Field1.Equals(right.Field1) || !left.Property1.Equals(right.Property1);\n    }\n}\n```\n\n### Generate Domain Events\n\nThe code shown below will generate three domain events. The GenerateDomainEvent attribute can be used on classes, structures, records, methods, constructors and properties. The GenerateDomainEvent attribute will inherit arguments from objects or members that will be implementing it.\n\n```csharp\nusing Minerals.AutoDomain;\n\nnamespace ExampleNamespace\n{\n    [AggregateRoot, GenerateDomainEvent(\"ExampleClassUpdatedDomainEvent\")]\n    public partial class ExampleClass\n    {\n        [GenerateDomainEvent(\"ExampleClassCreatedDomainEvent\")]\n        public ExampleClass(int exampleNumber, string exampleText)\n        {\n            // ...\n            AppendDomainEvent(new ExampleClassCreatedDomainEvent(Id, exampleNumber, exampleText));\n        }\n\n        // First argument: Name of the domain event\n        // Second argument: Should the domain event have the parent identifier as an argument\n        [GenerateDomainEvent(\"WorkDoneDomainEvent\", false)]\n        public void DoWork(int arg1, int arg2, int arg3)\n        {\n            // ...\n            AppendDomainEvent(new WorkDoneDomainEvent(arg1, arg2, arg3));\n        }\n    }\n}\n```\n\nThe code fragment shown above will generate the following domain events code, please notice that the generated events are in the ``Events`` sub-namespace.\n\n```csharp\n// \u003cauto-generated\u003e\n// This code was generated by a tool.\n// Name: Minerals.AutoDomain.Generators\n// Version: {Version}\n// \u003c/auto-generated\u003e\nnamespace ExampleNamespace.Events\n{\n    [global::System.Diagnostics.DebuggerNonUserCode]\n    [global::System.Runtime.CompilerServices.CompilerGenerated]\n    [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n    public readonly partial struct ExampleClassUpdatedDomainEvent : global::Minerals.AutoDomain.IDomainEvent, global::System.IEquatable\u003cExampleClassUpdatedDomainEvent\u003e\n    {\n        public ExampleClassId ExampleClassId { get; }\n\n        public ExampleClassUpdatedDomainEvent(ExampleClassId exampleClassId)\n        {\n            ExampleClassId = exampleClassId;\n        }\n\n        public bool Equals(ExampleClassUpdatedDomainEvent other)\n        {\n            return other.ExampleClassId.Equals(ExampleClassId);\n        }\n\n        public override bool Equals(object obj)\n        {\n            return obj is ExampleClassUpdatedDomainEvent other \u0026\u0026 other.ExampleClassId.Equals(ExampleClassId);\n        }\n\n        public override int GetHashCode()\n        {\n            return global::System.HashCode.Combine(ExampleClassId);\n        }\n\n        public static bool operator ==(ExampleClassUpdatedDomainEvent left, ExampleClassUpdatedDomainEvent right)\n        {\n            return left.ExampleClassId.Equals(right.ExampleClassId);\n        }\n\n        public static bool operator !=(ExampleClassUpdatedDomainEvent left, ExampleClassUpdatedDomainEvent right)\n        {\n            return !left.ExampleClassId.Equals(right.ExampleClassId);\n        }\n    }\n}\n\n// And\n\n// \u003cauto-generated\u003e\n// This code was generated by a tool.\n// Name: Minerals.AutoDomain.Generators\n// Version: {Version}\n// \u003c/auto-generated\u003e\nnamespace ExampleNamespace.Events\n{\n    [global::System.Diagnostics.DebuggerNonUserCode]\n    [global::System.Runtime.CompilerServices.CompilerGenerated]\n    [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n    public readonly partial struct ExampleClassCreatedDomainEvent : global::Minerals.AutoDomain.IDomainEvent, global::System.IEquatable\u003cExampleClassCreatedDomainEvent\u003e\n    {\n        public ExampleClassId ExampleClassId { get; }\n        public int ExampleNumber { get; }\n        public string ExampleText { get; }\n\n        public ExampleClassCreatedDomainEvent(ExampleClassId exampleClassId, int exampleNumber, string exampleText)\n        {\n            ExampleClassId = exampleClassId;\n            ExampleNumber = exampleNumber;\n            ExampleText = exampleText;\n        }\n\n        public bool Equals(ExampleClassCreatedDomainEvent other)\n        {\n            return other.ExampleClassId.Equals(ExampleClassId) \u0026\u0026 other.ExampleNumber.Equals(ExampleNumber) \u0026\u0026 other.ExampleText.Equals(ExampleText);\n        }\n\n        public override bool Equals(object obj)\n        {\n            return obj is ExampleClassCreatedDomainEvent other \u0026\u0026 other.ExampleClassId.Equals(ExampleClassId) \u0026\u0026 other.ExampleNumber.Equals(ExampleNumber) \u0026\u0026 other.ExampleText.Equals(ExampleText);\n        }\n\n        public override int GetHashCode()\n        {\n            return global::System.HashCode.Combine(ExampleClassId, ExampleNumber, ExampleText);\n        }\n\n        public static bool operator ==(ExampleClassCreatedDomainEvent left, ExampleClassCreatedDomainEvent right)\n        {\n            return left.ExampleClassId.Equals(right.ExampleClassId) \u0026\u0026 left.ExampleNumber.Equals(right.ExampleNumber) \u0026\u0026 left.ExampleText.Equals(right.ExampleText);\n        }\n\n        public static bool operator !=(ExampleClassCreatedDomainEvent left, ExampleClassCreatedDomainEvent right)\n        {\n            return !left.ExampleClassId.Equals(right.ExampleClassId) || !left.ExampleNumber.Equals(right.ExampleNumber) || !left.ExampleText.Equals(right.ExampleText);\n        }\n    }\n}\n\n// And\n\n// \u003cauto-generated\u003e\n// This code was generated by a tool.\n// Name: Minerals.AutoDomain.Generators\n// Version: {Version}\n// \u003c/auto-generated\u003e\nnamespace ExampleNamespace.Events\n{\n    [global::System.Diagnostics.DebuggerNonUserCode]\n    [global::System.Runtime.CompilerServices.CompilerGenerated]\n    [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n    public readonly partial struct WorkDoneDomainEvent : global::Minerals.AutoDomain.IDomainEvent, global::System.IEquatable\u003cWorkDoneDomainEvent\u003e\n    {\n        public int Arg1 { get; }\n        public int Arg2 { get; }\n        public int Arg3 { get; }\n\n        public WorkDoneDomainEvent(int arg1, int arg2, int arg3)\n        {\n            Arg1 = arg1;\n            Arg2 = arg2;\n            Arg3 = arg3;\n        }\n\n        public bool Equals(WorkDoneDomainEvent other)\n        {\n            return other.Arg1.Equals(Arg1) \u0026\u0026 other.Arg2.Equals(Arg2) \u0026\u0026 other.Arg3.Equals(Arg3);\n        }\n\n        public override bool Equals(object obj)\n        {\n            return obj is WorkDoneDomainEvent other \u0026\u0026 other.Arg1.Equals(Arg1) \u0026\u0026 other.Arg2.Equals(Arg2) \u0026\u0026 other.Arg3.Equals(Arg3);\n        }\n\n        public override int GetHashCode()\n        {\n            return global::System.HashCode.Combine(Arg1, Arg2, Arg3);\n        }\n\n        public static bool operator ==(WorkDoneDomainEvent left, WorkDoneDomainEvent right)\n        {\n            return left.Arg1.Equals(right.Arg1) \u0026\u0026 left.Arg2.Equals(right.Arg2) \u0026\u0026 left.Arg3.Equals(right.Arg3);\n        }\n\n        public static bool operator !=(WorkDoneDomainEvent left, WorkDoneDomainEvent right)\n        {\n            return !left.Arg1.Equals(right.Arg1) || !left.Arg2.Equals(right.Arg2) || !left.Arg3.Equals(right.Arg3);\n        }\n    }\n}\n```\n\n### Domain Event Dispatcher\n\nSince version 0.4.0, the package comes with a domain event dispatcher. Domain event handlers are automatically registered into the IoC container.\n\n```csharp\n// Adding to IoC container\nbuilder.Services.AddDomainEventDispatcher();\n\n// Dispatching domain events\nprivate readonly IDomainEventDispatcher _dispatcher;\n// ...\n_dispatcher.Dispatch(new ExampleDomainEvent(), cancellationToken);\n// ...\n\n// Handling of domain events\npublic class ExampleDomainEventHandler : IDomainEventHandler\u003cExampleDomainEvent\u003e\n{\n    public Task Handle(ExampleEvent domainEvent, CancellationToken cancellationToken)\n    {\n        // ...\n    }\n}\n```\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [branches on this repository](https://github.com/SzymonHalucha/Minerals.AutoDomain/branches).\n\n## Authors\n\n- **Szymon Hałucha** - Maintainer\n\nSee also the list of [contributors](https://github.com/SzymonHalucha/Minerals.AutoDomain/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.\n","funding_links":[],"categories":["Contributors Welcome for those","Source Generators"],"sub_categories":["1. [ThisAssembly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category","Domain Driven Design (DDD)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSzymonHalucha%2FMinerals.AutoDomain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSzymonHalucha%2FMinerals.AutoDomain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSzymonHalucha%2FMinerals.AutoDomain/lists"}