Skip to content

Commit

Permalink
Merge pull request dotnet#37103 from maryamariyan/di-external
Browse files Browse the repository at this point in the history
Adding DI.External to runtime with its history
  • Loading branch information
maryamariyan authored Jun 3, 2020
2 parents 33be17f + 77c69b9 commit dfbba33
Show file tree
Hide file tree
Showing 64 changed files with 264 additions and 2 deletions.
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());
}
}
}
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();
}
}
}
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);
}
}
}
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;
}
}
}
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();
}
}
}
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>
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);
}
}
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();
}
}
}
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>();
}
}
}
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Microsoft.Extensions.DependencyInjection.Specification
{
[ActiveIssue("https://github.com/dotnet/runtime/issues/33894", TestRuntimes.Mono)]
public abstract partial class DependencyInjectionSpecificationTests
{
public delegate object CreateInstanceFunc(IServiceProvider provider, Type type, object[] args);
Expand Down Expand Up @@ -41,6 +42,7 @@ public static IEnumerable<object[]> CreateInstanceFuncs

[Theory]
[MemberData(nameof(CreateInstanceFuncs))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/33894", TestRuntimes.Mono)]
public void TypeActivatorEnablesYouToCreateAnyTypeWithServicesEvenWhenNotInIocContainer(CreateInstanceFunc createFunc)
{
// Arrange
Expand All @@ -55,6 +57,7 @@ public void TypeActivatorEnablesYouToCreateAnyTypeWithServicesEvenWhenNotInIocCo

[Theory]
[MemberData(nameof(CreateInstanceFuncs))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/33894", TestRuntimes.Mono)]
public void TypeActivatorAcceptsAnyNumberOfAdditionalConstructorParametersToProvide(CreateInstanceFunc createFunc)
{
// Arrange
Expand Down Expand Up @@ -119,6 +122,7 @@ public void TypeActivatorWorksWithCtorWithOptionalArgs_WithStructDefaults(Create

[Theory]
[MemberData(nameof(CreateInstanceFuncs))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/33894", TestRuntimes.Mono)]
public void TypeActivatorCanDisambiguateConstructorsWithUniqueArguments(CreateInstanceFunc createFunc)
{
// Arrange
Expand Down Expand Up @@ -267,6 +271,7 @@ public void TypeActivatorThrowsWhenMarkedCtorDoesntAcceptArguments(CreateInstanc
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/33894", TestRuntimes.Mono)]
public void GetServiceOrCreateInstanceRegisteredServiceTransient()
{
// Reset the count because test order is not guaranteed
Expand All @@ -293,6 +298,7 @@ public void GetServiceOrCreateInstanceRegisteredServiceTransient()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/33894", TestRuntimes.Mono)]
public void GetServiceOrCreateInstanceRegisteredServiceSingleton()
{
lock (CreationCountFakeService.InstanceLock)
Expand Down Expand Up @@ -320,6 +326,7 @@ public void GetServiceOrCreateInstanceRegisteredServiceSingleton()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/33894", TestRuntimes.Mono)]
public void GetServiceOrCreateInstanceUnregisteredService()
{
lock (CreationCountFakeService.InstanceLock)
Expand Down
Loading

0 comments on commit dfbba33

Please sign in to comment.