use static factory nethod

This commit is contained in:
Julien LEICHER 2020-12-01 20:36:45 +01:00
parent 0e5c0d3b56
commit bdf1722f43
No known key found for this signature in database
GPG Key ID: BE0761B6A007EB96
2 changed files with 9 additions and 2 deletions

View File

@ -5,6 +5,7 @@ using HN.Domain;
using MediatR;
namespace HN.Application {
public class AddLinkCommand : IRequest<Guid>
{
public string Url { get; set; }
@ -21,11 +22,12 @@ namespace HN.Application {
public async Task<Guid> Handle(AddLinkCommand request, CancellationToken cancellationToken)
{
var link = new Link(request.Url);
var link = Link.FromUrl(request.Url);
await this._repository.AddAsync(link);
return link.Id;
}
}
}

View File

@ -8,11 +8,16 @@ namespace HN.Domain
public string Url { get; }
public DateTime CreatedAt { get; }
public Link(string url)
private Link(string url)
{
this.Id = Guid.NewGuid();
this.CreatedAt = DateTime.UtcNow;
this.Url = url;
}
public static Link FromUrl(string url)
{
return new Link(url);
}
}
}