Skip to content

Commit

Permalink
Enable Microsoft.Extensions.DependencyInjection (#33816)
Browse files Browse the repository at this point in the history
* Enables DI and Options
  • Loading branch information
maryamariyan authored Mar 22, 2020
1 parent cf63e73 commit 110804e
Show file tree
Hide file tree
Showing 39 changed files with 57 additions and 39 deletions.
17 changes: 15 additions & 2 deletions eng/referenceFromRuntime.targets
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,25 @@

<!-- transform back to path -->
<!-- We are adding two items(with and without aliases) for references having Aliases. The major reason behind this to not use the Aliases for all the types in that reference. -->
<!-- We can't use a Reference item for both since only the first one will be kept. Use ReferencePath for the second reference so it will still be passed to the compiler. -->
<!-- We can't use a Reference item for both since only the first one will be kept. -->
<!-- Aliases provides no way to encode both an alias and a non-aliased reference : https://github.com/dotnet/roslyn/issues/42604 -->
<!-- Use ReferencePath for the second reference so it will still be passed to the compiler. -->
<Reference Include="@(_filteredReferencePathFromRuntimeByFileName->'%(ReferencePath)')" />
<ReferencePath Include="@(_filteredReferencePathFromRuntimeByFileName->'%(ReferencePath)')" Condition="'%(_filteredReferencePathFromRuntimeByFileName.Aliases)' != ''" Aliases="" />
<_aliasedReferencePathFromRuntime Include="@(_filteredReferencePathFromRuntimeByFileName->'%(ReferencePath)')" Condition="'%(_filteredReferencePathFromRuntimeByFileName.Aliases)' != ''" />
<ReferencePath Include="@(_aliasedReferencePathFromRuntime)" Aliases=""/>
</ItemGroup>

<Error Condition="'@(_missingReferenceFromRuntime)' != ''"
Text="Could not resolve ReferenceFromRuntime item(s) '%(_missingReferenceFromRuntime.OriginalReferenceFromRuntime)' from '$(RuntimeProjectFile)'." />
</Target>

<Target Name="RemoveAliasedReferenceFromRuntime"
AfterTargets="CoreCompile"
Condition="'@(_aliasedReferencePathFromRuntime)' != ''">
<!-- SDK's GenerateBuildDependencyFile will break when they encounter two identical reference paths, fix by removing the aliased ones -->
<ItemGroup>
<ReferencePath Remove="@(_aliasedReferencePathFromRuntime)"/>
</ItemGroup>
</Target>

</Project>
11 changes: 4 additions & 7 deletions src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Configuration.EnvironmentVariables\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Configuration.FileExtensions\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Configuration.Ini\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.DependencyInjection\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.DependencyInjection.Abstractions\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.FileProviders.*\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.FileSystemGlobbing\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Hosting.Abstractions\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Logging.Abstractions\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Options\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Options.*\**\*csproj" />
<PortedExtensionsProject Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Primitives\**\*csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)*\ref\**\Microsoft.Extensions.*proj" Exclude="@(PortedExtensionsProject)" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)*\src\**\Microsoft.Extensions.*proj" Exclude="@(PortedExtensionsProject)" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)*\tests\Microsoft.Extensions.*.Tests.csproj" Exclude="@(PortedExtensionsProject)" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)*\tests\FunctionalTests\Microsoft.Extensions.Configuration.Functional.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)*\tests\Common\test\Microsoft.Extensions.Logging.Testing.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)*\tests\FunctionalTests\Microsoft.Extensions.Hosting.Functional.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)*\tests\TestApp\Microsoft.Extensions.Hosting.TestApp.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)*\tests\UnitTests\Microsoft.Extensions.Hosting.Unit.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)*\tests\Common\Microsoft.Extensions.Logging.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.*\tests\**\*.csproj" Exclude="@(PortedExtensionsProject)" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.*\tests\FunctionalTests\Microsoft.Extensions.Configuration.Functional.Tests.csproj"/>
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Common\tests\Extensions\**\*.csproj" />
</ItemGroup>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ------------------------------------------------------------------------------
// Changes to this file must follow the https://aka.ms/api-review process.
// ------------------------------------------------------------------------------

namespace Microsoft.Extensions.DependencyInjection
{
Expand Down Expand Up @@ -44,7 +47,7 @@ public void Dispose() { }
public partial class ServiceProviderOptions
{
public ServiceProviderOptions() { }
public bool ValidateOnBuild { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public bool ValidateScopes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public bool ValidateOnBuild { get { throw null; } set { } }
public bool ValidateScopes { get { throw null; } set { } }
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetFrameworkCurrent);net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<ExcludeCurrentFullFrameworkFromPackage>true</ExcludeCurrentFullFrameworkFromPackage>

<ILEmitBackend Condition="$(TargetFramework) != 'netstandard2.0'">True</ILEmitBackend>
<DefineConstants Condition="'$(ILEmitBackend)' == 'True'">$(DefineConstants);IL_EMIT</DefineConstants>

<!-- Debug IL generation -->
<ILEmitBackendSaveAssemblies>False</ILEmitBackendSaveAssemblies>
<DefineConstants Condition="'$(TargetFramework)' == 'net461' AND '$(ILEmitBackendSaveAssemblies)' == 'True'">$(DefineConstants);SAVE_ASSEMBLIES</DefineConstants>
<DefineConstants Condition="'$(TargetsNetFx)' == 'true' AND '$(ILEmitBackendSaveAssemblies)' == 'True'">$(DefineConstants);SAVE_ASSEMBLIES</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetsNetFx)' == 'true' Or '$(TargetFramework)' == 'netstandard2.0'">
<Reference Include="Microsoft.Bcl.AsyncInterfaces" />
<Reference Include="System.Threading.Tasks.Extensions" />
</ItemGroup>
Expand All @@ -27,6 +28,20 @@
<Reference Include="System.Core" />
</ItemGroup>

<ItemGroup Condition="'$(TargetsNetCoreApp)' == 'true'">
<Reference Include="System.Collections" />
<Reference Include="System.Collections.Concurrent" />
<Reference Include="System.ComponentModel" />
<Reference Include="System.Diagnostics.Tracing" />
<Reference Include="System.Linq" />
<Reference Include="System.Linq.Expressions" />
<Reference Include="System.Reflection.Emit.ILGeneration" />
<Reference Include="System.Reflection.Emit.Lightweight" />
<Reference Include="System.Reflection.Primitives" />
<Reference Include="System.Runtime" />
<Reference Include="System.Threading" />
</ItemGroup>

<ItemGroup>
<Compile Include="**\*.cs" />
<Compile Remove="ServiceLookup\ILEmit\**\*.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetFrameworkCurrent)</TargetFrameworks>
<RootNamespace>Microsoft.Extensions.DependencyInjection</RootNamespace>
<EnableDefaultItems>true</EnableDefaultItems>
</PropertyGroup>

<ItemGroup>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<Reference Include="Microsoft.Extensions.DependencyInjection.Specification.Tests" />
<Reference Include="Microsoft.Extensions.DependencyInjection" />
<Reference Include="Microsoft.Extensions.Logging.Abstractions" />
<Reference Include="Newtonsoft.Json" />
<Compile Include="..\..\Common\tests\Extensions\TestingUtils\Microsoft.AspNetCore.Testing\src\ExceptionAssertions.cs">
<Link>Common\tests\Extensions\TestingUtils\Microsoft.AspNetCore.Testing\src\ExceptionAssertions.cs</Link>
</Compile>
<Compile Include="..\..\Common\tests\Extensions\TestingUtils\Microsoft.AspNetCore.Testing\src\CultureReplacer.cs">
<Link>Common\tests\Extensions\TestingUtils\Microsoft.AspNetCore.Testing\src\CultureReplacer.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
<ReferenceFromRuntime Include="Microsoft.Extensions.DependencyInjection" />
<ReferenceFromRuntime Include="Microsoft.Extensions.DependencyInjection.Abstractions" Aliases="DIAbstractions" />
<None Update="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
extern alias DIAbstractions;

using System;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.DependencyInjection.Specification.Fakes;
using Xunit;

using AbstractionResources = Microsoft.Extensions.DependencyInjection.Abstractions.Resources;
using AbstractionsSR = DIAbstractions::System.SR;

namespace Microsoft.Extensions.DependencyInjection
{
Expand Down Expand Up @@ -350,7 +351,7 @@ public void TryAddEnumerable_ThrowsWhenAddingIndistinguishableImplementationType
ExceptionAssert.ThrowsArgument(
() => collection.TryAddEnumerable(descriptor),
"descriptor",
AbstractionResources.FormatTryAddIndistinguishableTypeToEnumerable(implementationType, serviceType));
AbstractionsSR.Format(AbstractionsSR.TryAddIndistinguishableTypeToEnumerable, implementationType, serviceType));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ServiceProviderCompilationTest
[InlineData(ServiceProviderMode.Runtime, typeof(I999))]
[InlineData(ServiceProviderMode.ILEmit, typeof(I999))]
[InlineData(ServiceProviderMode.Expressions, typeof(I999))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/33894", TestRuntimes.Mono)]
private async Task CompilesInLimitedStackSpace(ServiceProviderMode mode, Type serviceType)
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" Condition="'$(TargetsNetStandard)' != 'true' or '$(NETStandardVersion)' &gt;= 2.0" />
<PackageReference Include="System.Data.SqlClient" Version="$(SystemDataSqlClientVersion)" Condition="'$(TargetsNetStandard)' != 'true' or '$(NETStandardVersion)' &gt;= 2.0" />

<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" Condition="'$(TargetsNetStandard)' != 'true' or '$(NETStandardVersion)' &lt;= 2.0" />
<!-- Only include the assets from the direct packages we reference in the output -->
<PackageToInclude Include="@(PackageReference)" />
</ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions src/libraries/restore/netstandard/netstandard.depproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@
<PackageReference Include="System.Data.SqlClient">
<Version>4.7.0</Version>
</PackageReference>
<PackageReference Include="System.ComponentModel.Annotations">
<Version>4.7.0</Version>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 110804e

Please sign in to comment.