Conventions

Conventions can be used alongside manual configuration to set up data sources and values for properties that fit a specific profile.

This system is for doing things like:
  • Match any properties of type String which are called EmailAddress and apply an EmailDatasource to them
  • Match any properties that look like <Prefix>Name and apply a NameDatasource to them
  • TODO: Match any properties of type Role and use a shared instance to populate it instead of creating a new one

For example

A convention to set all String EmailAddress properties to use the EmailAddressSource
public class EmailAddressPropertyConvention : ITypePropertyConvention
{
    public void Apply(ITypePropertyConventionContext context)
    {
        context.SetSource<EmailAddressSource>();
    }

    public void SpecifyRequirements(ITypeMemberConventionRequirements requirements)
    {
        requirements.Name(x => String.Compare(x, "EmailAddress", true) == 0);
        requirements.Type(x => x == typeof(String));
    }
}

A convention to set all String EmailAddress fields to use the EmailAddressSource
public class EmailAddressFieldConvention : ITypeFieldConvention
{
    public void Apply(ITypeFieldConventionContext context)
    {
        context.SetSource<EmailAddressSource>();
    }

    public void SpecifyRequirements(ITypeMemberConventionRequirements requirements)
    {
        requirements.Name(x => String.Compare(x, "EmailAddress", true) == 0);
        requirements.Type(x => x == typeof(String));
    }
}

Last edited Apr 15, 2010 at 10:22 AM by robashton, version 2

Comments

jgossett Feb 14, 2013 at 10:27 PM 
Cool project.

Do you know if you specify a convention to a type. For example, a person?