{"action":"opened","issue":{"url":"https://api.github.com/repos/OData/WebApi/issues/220","labels_url":"https://api.github.com/repos/OData/WebApi/issues/220/labels{/name}","comments_url":"https://api.github.com/repos/OData/WebApi/issues/220/comments","events_url":"https://api.github.com/repos/OData/WebApi/issues/220/events","html_url":"https://github.com/OData/WebApi/issues/220","id":57258478,"number":220,"title":"Support Multiple Models with Attribute Routing","user":{"login":"abombss","id":9210,"avatar_url":"https://avatars.githubusercontent.com/u/9210?v=3","gravatar_id":"","url":"https://api.github.com/users/abombss","html_url":"https://github.com/abombss","followers_url":"https://api.github.com/users/abombss/followers","following_url":"https://api.github.com/users/abombss/following{/other_user}","gists_url":"https://api.github.com/users/abombss/gists{/gist_id}","starred_url":"https://api.github.com/users/abombss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abombss/subscriptions","organizations_url":"https://api.github.com/users/abombss/orgs","repos_url":"https://api.github.com/users/abombss/repos","events_url":"https://api.github.com/users/abombss/events{/privacy}","received_events_url":"https://api.github.com/users/abombss/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-11T00:08:54Z","updated_at":"2015-02-11T00:08:54Z","closed_at":null,"body":"When using OData Attribute Routing and the Attribute Routing Convention a single host cannot handle multiple EDM models.\r\n\r\nI am not sure the best solution to resolve this, here is the work around we came up with to solve this.\r\n\r\n```csharp\r\n    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]\r\n    public sealed class ODataModelAttribute : Attribute\r\n    {\r\n        public ODataModelAttribute(string containerFullName)\r\n        {\r\n            ContainerFullName = containerFullName;\r\n        }\r\n\r\n        public string ContainerFullName { get; private set; }\r\n    }\r\n\r\n    public class ModelBoundODataAttributeRoutingConvention : AttributeRoutingConvention\r\n    {\r\n        public override bool ShouldMapController(HttpControllerDescriptor controller)\r\n        {\r\n            if (controller == null)\r\n            {\r\n                return base.ShouldMapController(null);\r\n            }\r\n\r\n            var odataModelAttribute = controller.GetCustomAttributes<ODataModelAttribute>().FirstOrDefault();\r\n\r\n            if (odataModelAttribute == null)\r\n            {\r\n                return base.ShouldMapController(controller);\r\n            }\r\n\r\n            // This should be case sensitive since OData is case sensitive\r\n            return odataModelAttribute.ContainerFullName.Equals(\r\n                Model.EntityContainer.FullName(),\r\n                StringComparison.Ordinal);\r\n        }\r\n    }\r\n\r\n    public static class HttpConfigurationExtensions\r\n    {\r\n        public static ODataRoute MapModelBoundODataServiceRoute(\r\n            this HttpConfiguration configuration,\r\n            string routeName,\r\n            string routePrefix,\r\n            IEdmModel model)\r\n        {\r\n            var conventions =\r\n                (new[] { new ModelBoundODataAttributeRoutingConvention(model, configuration) }).Concat(\r\n                    ODataRoutingConventions.CreateDefault());\r\n\r\n            return System.Web.OData.Extensions.HttpConfigurationExtensions.MapODataServiceRoute(\r\n                configuration,\r\n                routeName,\r\n                routePrefix,\r\n                model,\r\n                new DefaultODataPathHandler(),\r\n                conventions);\r\n        }\r\n    }\r\n```\r\n\r\nAnd some sample usage.\r\n\r\n```csharp\r\nnamespace Sample \r\n{\r\n[ODataModel(\"Sample.Model1\")]\r\npublic class Model1Controller : ODataController\r\n{\r\n}\r\n\r\n[ODataModel(\"Sample.Model2\")]\r\npublic class Model2Controller : ODataController\r\n{\r\n}\r\n}\r\npublic static class ODataConfig\r\n{\r\n        public static void Register(HttpConfiguration config)\r\n        {\r\n            ODataModelBuilder model1Builder = new ODataConventionModelBuilder()\r\n            {\r\n                ContainerName = \"Model1\",\r\n                Namespace = \"Sample\",\r\n            }\r\n\r\n            model1Builder.EntitySet<Model1>(\"Model1\");\r\n\r\n            config.MapModelBoundODataServiceRoute(\r\n                \"OData-Model1\",\r\n                \"api/Model1\",\r\n                model1Builder.GetEdmModel());\r\n\r\n            ODataModelBuilder model2Builder = new ODataConventionModelBuilder()\r\n            {\r\n                ContainerName = \"Model2\",\r\n                Namespace = \"Sample\",\r\n            }\r\n\r\n            model1Builder.EntitySet<Model2>(\"Model2\");\r\n\r\n            config.MapModelBoundODataServiceRoute(\r\n                \"OData-Model2\",\r\n                \"api/Model2\",\r\n                model2Builder.GetEdmModel());                      \r\n        }\r\n}\r\n```\r\n"}}