Friday, March 6, 2015
How to add Multiple Regular Expression Validation attribute into one Property in ASP.Net MVC?
Create another new attribute and inherit from RegularExpressionAttribute
public class RegularExpressionAttribute : ValidationAttribute
{
private string _pattern;
public RegularExpressionAttribute(string pattern)
{
_pattern = pattern;
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value == null) return null;
if (!System.Text.RegularExpressions.Regex.IsMatch(value.ToString(), _pattern))
{
return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
}
return null;
}
public class RegularExpression2ndAttribute : RegularExpressionAttribute {}
So in view model:
[ValidURL(ErrorMessage = "Invalid URL")]
[RegularExpression(@"^.*\.(jpg|JPG|gif|GIF|jpeg)$", ErrorMessage = "Not a image URL")]
public string LogoUrl { get; set; }
Thursday, March 5, 2015
Wednesday, March 4, 2015
Friday, February 27, 2015
What is unit of work and relationship with CQRS/Event Sourcing?
See
http://martinfowler.com/eaaCatalog/unitOfWork.html
But I think this pattern is not applicable for CQRS/Event Sourcing, because SAGA is the way to deal with transaction in CQRS/Event Sourcing.
Reference:
https://msdn.microsoft.com/en-us/library/jj591569.aspx
http://martinfowler.com/eaaCatalog/unitOfWork.html
But I think this pattern is not applicable for CQRS/Event Sourcing, because SAGA is the way to deal with transaction in CQRS/Event Sourcing.
Reference:
https://msdn.microsoft.com/en-us/library/jj591569.aspx
Wednesday, February 25, 2015
What is Aggregate in DDD?
From Eric Evans book DDD Page 90
An AGGREGATE is a cluster of associated objects that we treat as a unit for the purpose of data changes. Each AGGREGATE has a root and a boundary. The boundary defines what is inside the AGGREGATE. The root is a single specific ENTITY contained in the AGGREGATE. The root is the only member of the AGGREGATE that outside objects are allowed to hold references to, although objects within the boundary may hold references to each other. ENTITIES other than the root have local identity, but it only needs to be unique within the aggregate, since no outside object can ever see it out of the context of the root ENTITY.
An AGGREGATE is a cluster of associated objects that we treat as a unit for the purpose of data changes. Each AGGREGATE has a root and a boundary. The boundary defines what is inside the AGGREGATE. The root is a single specific ENTITY contained in the AGGREGATE. The root is the only member of the AGGREGATE that outside objects are allowed to hold references to, although objects within the boundary may hold references to each other. ENTITIES other than the root have local identity, but it only needs to be unique within the aggregate, since no outside object can ever see it out of the context of the root ENTITY.
By Martin Fowler
a cluster of domain objects that can be treated as a single unit.
http://martinfowler.com/bliki/DDD_Aggregate.html
a cluster of domain objects that can be treated as a single unit.
http://martinfowler.com/bliki/DDD_Aggregate.html
Subscribe to:
Posts (Atom)