forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dotnet#37103 from maryamariyan/di-external
Adding DI.External to runtime with its history
- Loading branch information
Showing
64 changed files
with
264 additions
and
2 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Autofac.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,20 @@ | ||
// 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. | ||
|
||
using System; | ||
using Autofac; | ||
using Autofac.Extensions.DependencyInjection; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection.Specification | ||
{ | ||
public class AutofacDependencyInjectionSpecificationTests: DependencyInjectionSpecificationTests | ||
{ | ||
protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) | ||
{ | ||
var builder = new ContainerBuilder(); | ||
builder.Populate(serviceCollection); | ||
return new AutofacServiceProvider(builder.Build()); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/DryIoc.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,20 @@ | ||
// 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. | ||
|
||
using System; | ||
using DryIoc; | ||
using DryIoc.Microsoft.DependencyInjection; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection.Specification | ||
{ | ||
public class DryIocDependencyInjectionSpecificationTests: DependencyInjectionSpecificationTests | ||
{ | ||
protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) | ||
{ | ||
return new Container() | ||
.WithDependencyInjectionAdapter(serviceCollection) | ||
.BuildServiceProvider(); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Grace.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,24 @@ | ||
// 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. | ||
|
||
using System; | ||
using Grace.DependencyInjection; | ||
using Grace.DependencyInjection.Extensions; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection.Specification | ||
{ | ||
public class GraceDependencyInjectionSpecificationTests: SkippableDependencyInjectionSpecificationTests | ||
{ | ||
public override string[] SkippedTests => new[] | ||
{ | ||
"ResolvesMixedOpenClosedGenericsAsEnumerable", | ||
"TypeActivatorWorksWithCtorWithOptionalArgs_WithStructDefaults" | ||
}; | ||
|
||
protected override IServiceProvider CreateServiceProviderImpl(IServiceCollection serviceCollection) | ||
{ | ||
return new DependencyInjectionContainer().Populate(serviceCollection); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Lamar.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,22 @@ | ||
// 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. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection.Specification | ||
{ | ||
public class LamarDependencyInjectionSpecificationTests : SkippableDependencyInjectionSpecificationTests | ||
{ | ||
public override string[] SkippedTests => new[] | ||
{ | ||
"DisposesInReverseOrderOfCreation", | ||
"ResolvesMixedOpenClosedGenericsAsEnumerable" | ||
}; | ||
|
||
protected override IServiceProvider CreateServiceProviderImpl(IServiceCollection serviceCollection) | ||
{ | ||
return Lamar.Container.BuildAsync(serviceCollection).Result; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/LightInject.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,21 @@ | ||
// 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. | ||
|
||
using System; | ||
using Autofac; | ||
using Autofac.Extensions.DependencyInjection; | ||
using LightInject.Microsoft.DependencyInjection; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection.Specification | ||
{ | ||
public class LightInjectDependencyInjectionSpecificationTests: DependencyInjectionSpecificationTests | ||
{ | ||
protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) | ||
{ | ||
var builder = new ContainerBuilder(); | ||
builder.Populate(serviceCollection); | ||
return serviceCollection.CreateLightInjectServiceProvider(); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...I.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj
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,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>$(NetCoreAppCurrent);$(NetFrameworkCurrent)</TargetFrameworks> | ||
<EnableDefaultItems>true</EnableDefaultItems> | ||
<NoWarn>$(NoWarn);CS8002</NoWarn> | ||
<SignAssembly Condition="$(TargetFramework.StartsWith('net4'))">false</SignAssembly> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="$(CommonTestPath)Extensions\TestingUtils\Microsoft.AspNetCore.Testing\src\ExceptionAssertions.cs" | ||
Link="Common\tests\Extensions\TestingUtils\Microsoft.AspNetCore.Testing\src\ExceptionAssertions.cs" /> | ||
<Compile Include="$(CommonTestPath)Extensions\TestingUtils\Microsoft.AspNetCore.Testing\src\CultureReplacer.cs" | ||
Link="Common\tests\Extensions\TestingUtils\Microsoft.AspNetCore.Testing\src\CultureReplacer.cs" /> | ||
<Compile Include="..\DI.Specification.Tests\**\*.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ReferenceFromRuntime Include="Microsoft.Extensions.DependencyInjection" /> | ||
<ReferenceFromRuntime Include="Microsoft.Extensions.DependencyInjection.Abstractions" Aliases="DIAbstractions" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" /> | ||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.3.1"/> | ||
<PackageReference Include="DryIoc.Microsoft.DependencyInjection" Version="2.1.0"/> | ||
<PackageReference Include="Lamar.Microsoft.DependencyInjection" Version="2.0.1"/> | ||
<PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="2.2.0"/> | ||
<PackageReference Include="StructureMap.Microsoft.DependencyInjection" Version="1.4.0"/> | ||
<PackageReference Include="Grace.DependencyInjection.Extensions" Version="6.4.0"/> | ||
<PackageReference Include="Stashbox.Extensions.Dependencyinjection" Version="2.6.3"/> | ||
<PackageReference Include="Unity.Microsoft.DependencyInjection" Version="2.1.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
32 changes: 32 additions & 0 deletions
32
...ndencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.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,32 @@ | ||
// 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. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection.Specification | ||
{ | ||
public abstract class SkippableDependencyInjectionSpecificationTests: DependencyInjectionSpecificationTests | ||
{ | ||
public abstract string[] SkippedTests { get; } | ||
|
||
|
||
protected sealed override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) | ||
{ | ||
foreach (var stackFrame in new StackTrace(1).GetFrames().Take(2)) | ||
{ | ||
if (SkippedTests.Contains(stackFrame.GetMethod().Name)) | ||
{ | ||
// We skip tests by returning MEDI service provider that we know passes the test | ||
return serviceCollection.BuildServiceProvider(); | ||
} | ||
} | ||
|
||
return CreateServiceProviderImpl(serviceCollection); | ||
} | ||
|
||
protected abstract IServiceProvider CreateServiceProviderImpl(IServiceCollection serviceCollection); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/StashBox.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,16 @@ | ||
// 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. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection.Specification | ||
{ | ||
public class StashBoxDependencyInjectionSpecificationTests: DependencyInjectionSpecificationTests | ||
{ | ||
protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) | ||
{ | ||
return serviceCollection.UseStashbox(); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ibraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/StructureMap.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,29 @@ | ||
// 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. | ||
|
||
using System; | ||
using StructureMap; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection.Specification | ||
{ | ||
public class StructureMapDependencyInjectionSpecificationTests: SkippableDependencyInjectionSpecificationTests | ||
{ | ||
public override string[] SkippedTests => new[] | ||
{ | ||
"DisposesInReverseOrderOfCreation", | ||
"ResolvesMixedOpenClosedGenericsAsEnumerable" | ||
}; | ||
|
||
protected override IServiceProvider CreateServiceProviderImpl(IServiceCollection serviceCollection) | ||
{ | ||
var container = new Container(); | ||
container.Configure(config => | ||
{ | ||
config.Populate(serviceCollection); | ||
}); | ||
|
||
return container.GetInstance<IServiceProvider>(); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Unity.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,21 @@ | ||
// 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. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection.Specification | ||
{ | ||
public class UnityDependencyInjectionSpecificationTests: SkippableDependencyInjectionSpecificationTests | ||
{ | ||
public override string[] SkippedTests => new[] | ||
{ | ||
"SingletonServiceCanBeResolvedFromScope" | ||
}; | ||
|
||
protected override IServiceProvider CreateServiceProviderImpl(IServiceCollection serviceCollection) | ||
{ | ||
return Unity.Microsoft.DependencyInjection.ServiceProviderExtensions.BuildServiceProvider(serviceCollection); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.