Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KISS principle & fluent builder pattern #763

Merged
merged 8 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using Ardalis.GuardClauses;
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.Core.ContributorAggregate;
namespace NimblePros.SampleToDo.Core.ContributorAggregate;

public class Contributor : EntityBase, IAggregateRoot
{
public string Name { get; private set; }
public string Name { get; private set; } = default!;

public Contributor(string name)
{
Name = Guard.Against.NullOrEmpty(name, nameof(name));
SetName(name);
}

public void UpdateName(string newName)
{
Name = Guard.Against.NullOrEmpty(newName, nameof(newName));
SetName(newName);
}

public Contributor SetName(string newName)
aminsharifi marked this conversation as resolved.
Show resolved Hide resolved
aminsharifi marked this conversation as resolved.
Show resolved Hide resolved
{
this.Name = Guard.Against.NullOrEmpty(newName, nameof(newName));
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.Core.ContributorAggregate.Events;
namespace NimblePros.SampleToDo.Core.ContributorAggregate.Events;

/// <summary>
/// A domain event that is dispatched whenever a contributor is deleted.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using Ardalis.SharedKernel;
using NimblePros.SampleToDo.Core.ContributorAggregate.Events;
using NimblePros.SampleToDo.Core.ContributorAggregate.Events;
using NimblePros.SampleToDo.Core.ProjectAggregate;
using NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;
using MediatR;
using Microsoft.Extensions.Logging;

namespace NimblePros.SampleToDo.Core.ContributorAggregate.Handlers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.Specification;

namespace NimblePros.SampleToDo.Core.ContributorAggregate.Specifications;
namespace NimblePros.SampleToDo.Core.ContributorAggregate.Specifications;

public class ContributorByIdSpec : Specification<Contributor>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NimblePros.SampleToDo.Core.Interfaces;
using NimblePros.SampleToDo.Core.Services;

Expand Down
7 changes: 7 additions & 0 deletions sample/src/NimblePros.SampleToDo.Core/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
global using Ardalis.GuardClauses;
global using Ardalis.Result;
global using Ardalis.SharedKernel;
global using Ardalis.SmartEnum;
global using Ardalis.Specification;
global using MediatR;
global using Microsoft.Extensions.Logging;
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.Result;

namespace NimblePros.SampleToDo.Core.Interfaces;
namespace NimblePros.SampleToDo.Core.Interfaces;

public interface IDeleteContributorService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Ardalis.Result;
using NimblePros.SampleToDo.Core.ProjectAggregate;
using NimblePros.SampleToDo.Core.ProjectAggregate;

namespace NimblePros.SampleToDo.Core.Interfaces;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.Core.ProjectAggregate.Events;
namespace NimblePros.SampleToDo.Core.ProjectAggregate.Events;

public class ContributorAddedToItemEvent : DomainEventBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.Core.ProjectAggregate.Events;
namespace NimblePros.SampleToDo.Core.ProjectAggregate.Events;

public class NewItemAddedEvent : DomainEventBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.Core.ProjectAggregate.Events;
namespace NimblePros.SampleToDo.Core.ProjectAggregate.Events;

public class ToDoItemCompletedEvent : DomainEventBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Ardalis.GuardClauses;
using NimblePros.SampleToDo.Core.Interfaces;
using NimblePros.SampleToDo.Core.Interfaces;
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;
using MediatR;

namespace NimblePros.SampleToDo.Core.ProjectAggregate.Handlers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.SmartEnum;

namespace NimblePros.SampleToDo.Core.ProjectAggregate;
namespace NimblePros.SampleToDo.Core.ProjectAggregate;

public class PriorityStatus : SmartEnum<PriorityStatus>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.GuardClauses;
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;
using Ardalis.SharedKernel;
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;

namespace NimblePros.SampleToDo.Core.ProjectAggregate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.Specification;

namespace NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;
namespace NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;

public class IncompleteItemsSearchSpec : Specification<ToDoItem>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.Specification;

namespace NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;
namespace NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;

public class IncompleteItemsSpec : Specification<ToDoItem>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.Specification;

namespace NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;
namespace NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;

public class ProjectByIdWithItemsSpec : Specification<Project>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.Specification;

namespace NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;
namespace NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;

public class ProjectsWithItemsByContributorIdSpec : Specification<Project>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ardalis.GuardClauses;
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;
using Ardalis.SharedKernel;
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;

namespace NimblePros.SampleToDo.Core.ProjectAggregate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using Ardalis.Result;
using NimblePros.SampleToDo.Core.ContributorAggregate;
using NimblePros.SampleToDo.Core.ContributorAggregate;
using NimblePros.SampleToDo.Core.ContributorAggregate.Events;
using NimblePros.SampleToDo.Core.Interfaces;
using Ardalis.SharedKernel;
using MediatR;
using Microsoft.Extensions.Logging;

namespace NimblePros.SampleToDo.Core.Services;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Ardalis.Result;
using NimblePros.SampleToDo.Core.Interfaces;
using NimblePros.SampleToDo.Core.Interfaces;
using NimblePros.SampleToDo.Core.ProjectAggregate;
using NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.Core.Services;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NimblePros.SampleToDo.UseCases.Contributors;
using NimblePros.SampleToDo.UseCases.Contributors.List;
using NimblePros.SampleToDo.UseCases.Contributors.Queries.List;

namespace NimblePros.SampleToDo.Infrastructure.Data.Queries;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NimblePros.SampleToDo.UseCases.Contributors;
using NimblePros.SampleToDo.UseCases.Contributors.List;
using Microsoft.EntityFrameworkCore;
using NimblePros.SampleToDo.UseCases.Contributors.Queries.List;

namespace NimblePros.SampleToDo.Infrastructure.Data.Queries;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using NimblePros.SampleToDo.Infrastructure.Data;
using NimblePros.SampleToDo.Infrastructure.Data.Queries;
using NimblePros.SampleToDo.Infrastructure.Email;
using NimblePros.SampleToDo.UseCases.Contributors.List;
using NimblePros.SampleToDo.UseCases.Contributors.Queries.List;
using NimblePros.SampleToDo.UseCases.Projects.ListIncompleteItems;
using NimblePros.SampleToDo.UseCases.Projects.ListShallow;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Ardalis.Result;

namespace NimblePros.SampleToDo.UseCases.Contributors.Create;
namespace NimblePros.SampleToDo.UseCases.Contributors.Commands.Create;

/// <summary>
/// Create a new Contributor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Ardalis.SharedKernel;
using NimblePros.SampleToDo.Core.ContributorAggregate;

namespace NimblePros.SampleToDo.UseCases.Contributors.Create;
namespace NimblePros.SampleToDo.UseCases.Contributors.Commands.Create;

public class CreateContributorHandler : ICommandHandler<CreateContributorCommand, Result<int>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Ardalis.Result;
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.UseCases.Contributors.Delete;
namespace NimblePros.SampleToDo.UseCases.Contributors.Commands.Delete;

public record DeleteContributorCommand(int ContributorId) : ICommand<Result>;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Ardalis.SharedKernel;
using NimblePros.SampleToDo.Core.Interfaces;

namespace NimblePros.SampleToDo.UseCases.Contributors.Delete;
namespace NimblePros.SampleToDo.UseCases.Contributors.Commands.Delete;

public class DeleteContributorHandler : ICommandHandler<DeleteContributorCommand, Result>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Ardalis.Result;
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.UseCases.Contributors.Update;
namespace NimblePros.SampleToDo.UseCases.Contributors.Commands.Update;

public record UpdateContributorCommand(int ContributorId, string NewName) : ICommand<Result<ContributorDTO>>;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Ardalis.SharedKernel;
using NimblePros.SampleToDo.Core.ContributorAggregate;

namespace NimblePros.SampleToDo.UseCases.Contributors.Update;
namespace NimblePros.SampleToDo.UseCases.Contributors.Commands.Update;

public class UpdateContributorHandler : ICommandHandler<UpdateContributorCommand, Result<ContributorDTO>>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using NimblePros.SampleToDo.Core.ContributorAggregate;
using NimblePros.SampleToDo.Core.ContributorAggregate.Specifications;

namespace NimblePros.SampleToDo.UseCases.Contributors.Get;
namespace NimblePros.SampleToDo.UseCases.Contributors.Queries.Get;

/// <summary>
/// Queries don't necessarily need to use repository methods, but they can if it's convenient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Ardalis.Result;
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.UseCases.Contributors.Get;
namespace NimblePros.SampleToDo.UseCases.Contributors.Queries.Get;

public record GetContributorQuery(int ContributorId) : IQuery<Result<ContributorDTO>>;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NimblePros.SampleToDo.UseCases.Contributors.List;
namespace NimblePros.SampleToDo.UseCases.Contributors.Queries.List;

/// <summary>
/// Represents a service that will actually fetch the necessary data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Ardalis.Result;
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.UseCases.Contributors.List;
namespace NimblePros.SampleToDo.UseCases.Contributors.Queries.List;

public class ListContributorsHandler : IQueryHandler<ListContributorsQuery, Result<IEnumerable<ContributorDTO>>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Ardalis.Result;
using Ardalis.SharedKernel;

namespace NimblePros.SampleToDo.UseCases.Contributors.List;
namespace NimblePros.SampleToDo.UseCases.Contributors.Queries.List;

public record ListContributorsQuery(int? Skip, int? Take) : IQuery<Result<IEnumerable<ContributorDTO>>>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FastEndpoints;
using NimblePros.SampleToDo.UseCases.Contributors.Create;
using MediatR;
using NimblePros.SampleToDo.UseCases.Contributors.Commands.Create;

namespace NimblePros.SampleToDo.Web.Contributors;

Expand Down
6 changes: 3 additions & 3 deletions sample/src/NimblePros.SampleToDo.Web/Contributors/Delete.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FastEndpoints;
using Ardalis.Result;
using Ardalis.Result;
using FastEndpoints;
using MediatR;
using NimblePros.SampleToDo.UseCases.Contributors.Delete;
using NimblePros.SampleToDo.UseCases.Contributors.Commands.Delete;

namespace NimblePros.SampleToDo.Web.Contributors;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Ardalis.Result;
using FastEndpoints;
using MediatR;
using NimblePros.SampleToDo.UseCases.Contributors.Get;
using NimblePros.SampleToDo.UseCases.Contributors.Queries.Get;

namespace NimblePros.SampleToDo.Web.Contributors;

Expand Down
2 changes: 1 addition & 1 deletion sample/src/NimblePros.SampleToDo.Web/Contributors/List.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FastEndpoints;
using MediatR;
using NimblePros.SampleToDo.UseCases.Contributors.List;
using NimblePros.SampleToDo.UseCases.Contributors.Queries.List;

namespace NimblePros.SampleToDo.Web.Contributors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using FastEndpoints;
using MediatR;
using NimblePros.SampleToDo.Core.ContributorAggregate;
using NimblePros.SampleToDo.UseCases.Contributors.Update;
using NimblePros.SampleToDo.UseCases.Contributors.Commands.Update;

namespace NimblePros.SampleToDo.Web.Contributors;

Expand Down
2 changes: 1 addition & 1 deletion sample/src/NimblePros.SampleToDo.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
using Serilog;
using Microsoft.EntityFrameworkCore;
using NimblePros.SampleToDo.Core.ProjectAggregate;
using NimblePros.SampleToDo.UseCases.Contributors.Create;
using Serilog.Extensions.Logging;
using NimblePros.SampleToDo.UseCases.Contributors.Commands.Create;

var logger = Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using NimblePros.SampleToDo.Infrastructure.Data;
using NimblePros.SampleToDo.Web;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NimblePros.SampleToDo.UseCases.Contributors.Create;
using NimblePros.SampleToDo.Infrastructure.Data;
using NimblePros.SampleToDo.UseCases.Contributors.Commands.Create;
using NimblePros.SampleToDo.Web;

namespace NimblePros.SampleToDo.FunctionalTests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Ardalis.SharedKernel;
using FluentAssertions;
using NimblePros.SampleToDo.Core.ContributorAggregate;
using NimblePros.SampleToDo.UseCases.Contributors.Create;
using NimblePros.SampleToDo.UseCases.Contributors.Commands.Create;
using NSubstitute;
using Xunit;

Expand Down
Loading