roydukkey / Dado.ComponentModel.Mutations

Provides attributes that are used to help ensure data integrity for objects used as data sources.
https://www.nuget.org/packages/Dado.ComponentModel.Mutations
Apache License 2.0
8 stars 0 forks source link

What calls mutate? #14

Closed grosch closed 3 years ago

grosch commented 4 years ago

This is a pretty cool library, thanks! What's not clear to me though is, what actually triggers the mutation since this isn't a normal ability of an Attribute.

roydukkey commented 4 years ago

Hey. Thanks! Nothing automatically triggers the mutation. The mutation needs to be hooked into the process of your choosing. I would expect people to normally mutate before saving to model to the database or before validating data. Here is an example code block.

public partial class ApplicationUser
{
    [ToLower, RegexReplace(@"[^a-z0-9_]")]
    public virtual string UserName { get; set; }
}

var user = new ApplicationUser() {
    UserName = "M@X_speed.01!"
}

// Then to perform mutation
new MutationContext<ApplicationUser>(user).Mutate();