diff --git a/src/Microsoft.Restier.EntityFramework/Model/ModelProducer.cs b/src/Microsoft.Restier.EntityFramework/Model/ModelProducer.cs index a8abb32c..26838090 100644 --- a/src/Microsoft.Restier.EntityFramework/Model/ModelProducer.cs +++ b/src/Microsoft.Restier.EntityFramework/Model/ModelProducer.cs @@ -71,10 +71,7 @@ private static IDictionary { PrimitiveTypeKind.Time, EdmPrimitiveTypeKind.Duration } }; - static ModelProducer() - { - Instance = new ModelProducer(); - } + private static IModelBuilder instance; private ModelProducer() { @@ -83,7 +80,18 @@ private ModelProducer() /// /// Gets the single instance of this model producer. /// - public static ModelProducer Instance { get; private set; } + public static IModelBuilder Instance + { + get + { + if (instance == null) + { + instance = new ModelProducer(); + } + + return instance; + } + } /// public Task GetModelAsync(InvocationContext context, CancellationToken cancellationToken) diff --git a/src/Microsoft.Restier.WebApi/Routing/RestierRoutingConvention.cs b/src/Microsoft.Restier.WebApi/Routing/RestierRoutingConvention.cs index 8d28c8b3..cf4cb567 100644 --- a/src/Microsoft.Restier.WebApi/Routing/RestierRoutingConvention.cs +++ b/src/Microsoft.Restier.WebApi/Routing/RestierRoutingConvention.cs @@ -115,13 +115,18 @@ private static bool HasControllerForEntitySetOrSingleton( ODataPathSegment firstSegment = odataPath.Segments.FirstOrDefault(); if (firstSegment != null) { - if (firstSegment is EntitySetPathSegment) + var entitySetSegment = firstSegment as EntitySetPathSegment; + if (entitySetSegment != null) { - controllerName = (firstSegment as EntitySetPathSegment).EntitySetName; + controllerName = entitySetSegment.EntitySetName; } - else if (firstSegment is SingletonPathSegment) + else { - controllerName = (firstSegment as SingletonPathSegment).SingletonName; + var singletonSegment = firstSegment as SingletonPathSegment; + if (singletonSegment != null) + { + controllerName = singletonSegment.SingletonName; + } } }