-
Notifications
You must be signed in to change notification settings - Fork 17
Changes From 2.5 to 3.0
Alexander I. Zaytsev edited this page May 18, 2013
·
10 revisions
- Removed
ExtendedMvcApplicationand all adapter specified application classes.ExtendedMvcApplication.Bootstrapperproperty has been moved toBootstrapper.Currentstatic property. This means that now you have to use standartHttpApplication
public class MvcApplication : HttpApplication
{
public MvcApplication()
{
Bootstrapper.Current.BootstrapperTasks
.Include<RegisterModelMetadata>()
.Include<RegisterControllers>()
.Include<ConfigureFilters>()
.Include<ConfigureModelBinders>()
.Include<RegisterRoutes>()
.Include<RegisterActionInvokers>();
}
}- Model metadata configuration moved into separate assembly
Examples (how to use as a standalone assembly):
-
FluentMetadataConfiguration.Register() simple way to register your configurations (metadata configuration classes must have default constructor)
-
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();- Add better support for ReSharper via JetBrains.Annotations
- 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;
}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());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)