use static factory nethod
This commit is contained in:
parent
0e5c0d3b56
commit
bdf1722f43
@ -5,6 +5,7 @@ using HN.Domain;
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
|
|
||||||
namespace HN.Application {
|
namespace HN.Application {
|
||||||
|
|
||||||
public class AddLinkCommand : IRequest<Guid>
|
public class AddLinkCommand : IRequest<Guid>
|
||||||
{
|
{
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
@ -21,11 +22,12 @@ namespace HN.Application {
|
|||||||
|
|
||||||
public async Task<Guid> Handle(AddLinkCommand request, CancellationToken cancellationToken)
|
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);
|
await this._repository.AddAsync(link);
|
||||||
|
|
||||||
return link.Id;
|
return link.Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,11 +8,16 @@ namespace HN.Domain
|
|||||||
public string Url { get; }
|
public string Url { get; }
|
||||||
public DateTime CreatedAt { get; }
|
public DateTime CreatedAt { get; }
|
||||||
|
|
||||||
public Link(string url)
|
private Link(string url)
|
||||||
{
|
{
|
||||||
this.Id = Guid.NewGuid();
|
this.Id = Guid.NewGuid();
|
||||||
this.CreatedAt = DateTime.UtcNow;
|
this.CreatedAt = DateTime.UtcNow;
|
||||||
this.Url = url;
|
this.Url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Link FromUrl(string url)
|
||||||
|
{
|
||||||
|
return new Link(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user