{"action":"created","issue":{"url":"https://api.github.com/repos/MehdiK/Humanizer/issues/413","labels_url":"https://api.github.com/repos/MehdiK/Humanizer/issues/413/labels{/name}","comments_url":"https://api.github.com/repos/MehdiK/Humanizer/issues/413/comments","events_url":"https://api.github.com/repos/MehdiK/Humanizer/issues/413/events","html_url":"https://github.com/MehdiK/Humanizer/issues/413","id":74419904,"number":413,"title":"Getting HumanizerMetadataProvider to work in vNext","user":{"login":"mrchief","id":781818,"avatar_url":"https://avatars.githubusercontent.com/u/781818?v=3","gravatar_id":"","url":"https://api.github.com/users/mrchief","html_url":"https://github.com/mrchief","followers_url":"https://api.github.com/users/mrchief/followers","following_url":"https://api.github.com/users/mrchief/following{/other_user}","gists_url":"https://api.github.com/users/mrchief/gists{/gist_id}","starred_url":"https://api.github.com/users/mrchief/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrchief/subscriptions","organizations_url":"https://api.github.com/users/mrchief/orgs","repos_url":"https://api.github.com/users/mrchief/repos","events_url":"https://api.github.com/users/mrchief/events{/privacy}","received_events_url":"https://api.github.com/users/mrchief/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-08T16:33:30Z","updated_at":"2015-05-11T17:10:40Z","closed_at":null,"body":"Seems like `DataAnnotationsModelMetadataProvider` is gone in vNext. Instead there is a `DataAnnotationsMetadataProvider` but it doesn't expose any virtual members to override.\r\n\r\nThis is my attempt based on the `DefaultModelMetadataProvider` not sure if this is the right way to go:\r\n\r\n```csharp\r\n\r\npublic class HumanizerMetadataProvider : DefaultModelMetadataProvider\r\n{\r\n\tprotected override ModelMetadata CreateModelMetadata(DefaultMetadataDetailsCache entry)\r\n\t{\r\n\t    var propertyAttributes = entry.Attributes;\r\n\t    var modelMetadata = entry.DisplayMetadata;\r\n\r\n        if (IsTransformRequired(modelMetadata, propertyAttributes))\r\n            modelMetadata.DisplayName = modelMetadata.SimpleDisplayProperty.Humanize().Transform(To.TitleCase);\r\n\r\n        return base.CreateModelMetadata(entry);\r\n\t}\r\n\r\n\r\n\tprivate static bool IsTransformRequired(DisplayMetadata modelMetadata, IReadOnlyList<object> propertyAttributes)\r\n\t{\r\n\t\tif (string.IsNullOrEmpty(modelMetadata.SimpleDisplayProperty))\r\n\t\t\treturn false;\r\n\r\n\t\tif (propertyAttributes.OfType<DisplayNameAttribute>().Any())\r\n\t\t\treturn false;\r\n\r\n\t\tif (propertyAttributes.OfType<DisplayAttribute>().Any())\r\n\t\t\treturn false;\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic HumanizerMetadataProvider(ICompositeMetadataDetailsProvider detailsProvider) : base(detailsProvider)\r\n\t{\r\n\t}\r\n}\r\n```\r\n\r\nI still haven't figured out how to plug this in so that it replaces the default. "},"comment":{"url":"https://api.github.com/repos/MehdiK/Humanizer/issues/comments/100981150","html_url":"https://github.com/MehdiK/Humanizer/issues/413#issuecomment-100981150","issue_url":"https://api.github.com/repos/MehdiK/Humanizer/issues/413","id":100981150,"user":{"login":"mrchief","id":781818,"avatar_url":"https://avatars.githubusercontent.com/u/781818?v=3","gravatar_id":"","url":"https://api.github.com/users/mrchief","html_url":"https://github.com/mrchief","followers_url":"https://api.github.com/users/mrchief/followers","following_url":"https://api.github.com/users/mrchief/following{/other_user}","gists_url":"https://api.github.com/users/mrchief/gists{/gist_id}","starred_url":"https://api.github.com/users/mrchief/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrchief/subscriptions","organizations_url":"https://api.github.com/users/mrchief/orgs","repos_url":"https://api.github.com/users/mrchief/repos","events_url":"https://api.github.com/users/mrchief/events{/privacy}","received_events_url":"https://api.github.com/users/mrchief/received_events","type":"User","site_admin":false},"created_at":"2015-05-11T17:10:40Z","updated_at":"2015-05-11T17:10:40Z","body":"Based on the [discussion](https://github.com/aspnet/Mvc/issues/2522#event-301956164) with aspnet team, here's the vNext compatible version:\r\n\r\n```csharp\r\npublic class HumanizerMetadataProvider : IDisplayMetadataProvider\r\n{\r\n  private static bool IsTransformRequired(DisplayMetadata modelMetadata, IReadOnlyList<object> propertyAttributes)\r\n  {\r\n      if (string.IsNullOrEmpty(modelMetadata.SimpleDisplayProperty))\r\n          return false;\r\n\r\n      if (propertyAttributes.OfType<DisplayNameAttribute>().Any())\r\n          return false;\r\n\r\n      if (propertyAttributes.OfType<DisplayAttribute>().Any())\r\n          return false;\r\n\r\n      return true;\r\n  }\r\n\r\n  /// <summary>\r\n  /// Gets the values for properties of <see cref=\"T:Microsoft.AspNet.Mvc.ModelBinding.Metadata.DisplayMetadata\"/>. \r\n  /// </summary>\r\n  /// <param name=\"context\">The <see cref=\"T:Microsoft.AspNet.Mvc.ModelBinding.Metadata.DisplayMetadataProviderContext\"/>.</param>\r\n  public void GetDisplayMetadata(DisplayMetadataProviderContext context)\r\n  {\r\n      var propertyAttributes = context.Attributes;\r\n      var modelMetadata = context.DisplayMetadata;\r\n\r\n      if (IsTransformRequired(modelMetadata, propertyAttributes))\r\n          modelMetadata.DisplayName = modelMetadata.SimpleDisplayProperty.Humanize().Transform(To.TitleCase);\r\n  }\r\n}\r\n```"}}