Skip to content

Changes From 2.5 to 3.0

Alexander I. Zaytsev edited this page May 18, 2013 · 10 revisions

Alpha1000

  • Removed ExtendedMvcApplication and all adapter specified application classes. ExtendedMvcApplication.Bootstrapper property has been moved to Bootstrapper.Current static property. This means that now you have to use standart HttpApplication
    public class MvcApplication : HttpApplication
    {
        public MvcApplication()
        {
            Bootstrapper.Current.BootstrapperTasks
                .Include<RegisterModelMetadata>()
                .Include<RegisterControllers>()
                .Include<ConfigureFilters>()
                .Include<ConfigureModelBinders>()
                .Include<RegisterRoutes>()
                .Include<RegisterActionInvokers>();
        }
    }

Alpha1002

  • Model metadata configuration moved into separate assembly

Examples (how to use as a standalone assembly):

  1. FluentMetadataConfiguration.Register() simple way to register your configurations (metadata configuration classes must have default constructor)

  2. Using with IoC containers:

Windsor:

    FluentMetadataConfiguration
        .RegisterEachConfigurationWithContainer(
            data => container.Register(
                Component
                    .For(data.InterfaceType).ImplementedBy(data.MetadataConfigurationType)
                    .LifestyleTransient()))
        .ConstructMetadataUsing(container.ResolveAll<IModelMetadataConfiguration>)
        .Register();

Autofac:

    var builder = new ContainerBuilder();
    FluentMetadataConfiguration
        .RegisterEachConfigurationWithContainer(r => builder.RegisterType(r.MetadataConfigurationType).As(r.InterfaceType));

    DependencyResolver.SetResolver(new AutofacDependencyResolver(builder.Build()));

    FluentMetadataConfiguration.Register();

Usage without countainer:

FluentMetadataConfiguration.Register();

Alpha1010

  • Add better support for ReSharper via JetBrains.Annotations

Alpha1011

  • Add interface IModelMetadataItemBuilder<> which allows to more easily create extensions for collection item, because of the interface covariance. Now it is possible to write extensions with following signatures
public static IModelMetadataItemBuilder<IEnumerable<T>> MyExtensionsMethod<T>(
        this IModelMetadataItemBuilder<IEnumerable<T>> builder, string someArg) 
    { 
        // body
        return builder; 
    }

Alpha1013

Added conventions support for property metadata

By default, all models that have ModelMetadataConfiguration will accept conventions. To change this be

FluentMetadataConfiguration.Registry.ConventionAcceptor = new CustomModelConventionAcceptor();

where CustomModelConventionAcceptor can look like:

public class CustomModelConventionAcceptor : DefaultModelConventionAcceptor
{
	public override bool CanAcceptConventions(AcceptorContext context)
	{
                // where IForm is your custom interface for models
		return base.CanAcceptConventions(context) || typeof(IForm).IsAssignableFrom(context.ModelType);
	}
}

or you can create completely your own version of acceptor by implementing IModelConventionAcceptor.

Conventions for properties:

public class NamePropertyMetadataConvention : DefaultPropertyMetadataConvention<string>
{
        // 
	protected override bool CanBeAcceptedCore(PropertyInfo propertyInfo)
	{
		return propertyInfo.Name == "Name";
	}

	protected override void CreateMetadataRulesCore(ModelMetadataItemBuilder<string> builder)
	{
		builder
			.Required()
			.MaximumLength(50);
	}
}

Register convention with registry;

FluentMetadataConfiguration.Registry.RegisterConvention(new NamePropertyMetadataConvention());

Conventional internationalization and localization

To enable convention set default resource type

ConventionSettings.DefaultResourceType = typeof(Resources.LocalizedTexts);
  • Default convention for display name: ModelClassName_PropertyName; if no matches found, resource PropertyName will be used; otherwise, property name will be splitted to words (ex., PropertyName -> Property Name).
  • Default convention for validation messages - ModelClassName_PropertyName_AttributeName, then Validation_AttributeName (ex, Validation_Required)

Clone this wiki locally