-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[main] Update dependencies from dotnet/runtime (#24861)
[main] Update dependencies from dotnet/runtime - Workaround reflection bug in OData OData was locating ServiceCollectionContainerBuilderExtensions in the same assembly as ServiceCollection. This broke when ServiceCollection was pushed down to another assembly. This works around it by avoiding reflection and directly calling ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(this IServiceCollection). This commit can be reverted when picking up an OData package with OData/WebApi@1528766 - Update dependencies from dotnet/runtime manually '6.0.0-preview.5.21260.6' => '6.0.0-preview.5.21263.7' (from build '20210513.7' of 'https://github.com/dotnet/runtime')
- Loading branch information
1 parent
14da5d9
commit d277e0c
Showing
4 changed files
with
97 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
test/EFCore.OData.FunctionalTests/Query/WorkaroundContainerBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.OData; | ||
|
||
namespace Microsoft.AspNet.OData | ||
{ | ||
// This is a copy of https://github.com/OData/WebApi/blob/757631faf10b494e55117904196e8aa45d4c764d/src/Microsoft.AspNet.OData.Shared/DefaultContainerBuilder.cs | ||
// with a fix for reflection issue in BuildContainer | ||
// This can be removed once an OData package is available with https://github.com/OData/WebApi/commit/1528766b49b8dd49dd8845d8ea5e2973268eeee4 | ||
public class WorkaroundContainerBuilder : IContainerBuilder | ||
{ | ||
private readonly IServiceCollection services = new ServiceCollection(); | ||
|
||
public virtual IContainerBuilder AddService(Microsoft.OData.ServiceLifetime lifetime, Type serviceType,Type implementationType) | ||
{ | ||
services.Add(new ServiceDescriptor( | ||
serviceType ?? throw new ArgumentNullException(nameof(serviceType)), | ||
implementationType ?? throw new ArgumentNullException(nameof(implementationType)), | ||
TranslateServiceLifetime(lifetime))); | ||
|
||
return this; | ||
} | ||
|
||
public IContainerBuilder AddService(Microsoft.OData.ServiceLifetime lifetime, Type serviceType, Func<IServiceProvider, object> implementationFactory) | ||
{ | ||
services.Add(new ServiceDescriptor( | ||
serviceType ?? throw new ArgumentNullException(nameof(serviceType)), | ||
implementationFactory ?? throw new ArgumentNullException(nameof(implementationFactory)), | ||
TranslateServiceLifetime(lifetime))); | ||
|
||
return this; | ||
} | ||
|
||
public virtual IServiceProvider BuildContainer() => services.BuildServiceProvider(); // workaround is here, don't use reflection to call BuildServiceProvider | ||
|
||
private static Microsoft.Extensions.DependencyInjection.ServiceLifetime TranslateServiceLifetime(Microsoft.OData.ServiceLifetime lifetime) => lifetime switch | ||
{ | ||
Microsoft.OData.ServiceLifetime.Scoped => Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, | ||
Microsoft.OData.ServiceLifetime.Singleton => Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton, | ||
_ => Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient | ||
}; | ||
} | ||
} |