-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Adding support for constrained open generics to DI #34393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
05b0be1
Porting changes from https://github.com/dotnet/extensions/pull/536
jbogard 3e43d9c
Adding resource string
jbogard e205b37
Compile error
jbogard 3f1b86c
Removing AbstractClass in Fakes in favor of new AbstractClass in the …
jbogard 4943e59
Merge branch 'master' into ConstrainedOpenGenerics
jbogard aa71caa
Adding external DI tests and fixing solution file
jbogard 0958470
Merge branch 'master' into ConstrainedOpenGenerics
jbogard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
10 changes: 10 additions & 0 deletions
10
...rosoft.Extensions.DependencyInjection/tests/DI.Specification.Tests/Fakes/AbstractClass.cs
This file contains hidden or 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,10 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection.Specification.Fakes | ||
| { | ||
| public abstract class AbstractClass | ||
| { | ||
|
|
||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...ns.DependencyInjection/tests/DI.Specification.Tests/Fakes/ClassImplementingIComparable.cs
This file contains hidden or 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,13 @@ | ||
| // 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.Fakes | ||
| { | ||
| public class ClassImplementingIComparable : IComparable<ClassImplementingIComparable> | ||
| { | ||
| public int CompareTo(ClassImplementingIComparable other) => 0; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
...ns.DependencyInjection/tests/DI.Specification.Tests/Fakes/ClassImplementingIEnumerable.cs
This file contains hidden or 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,14 @@ | ||
| // 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.Collections; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection.Specification.Fakes | ||
| { | ||
| public class ClassImplementingIEnumerable : IEnumerable | ||
| { | ||
| public IEnumerator GetEnumerator() => throw new NotImplementedException(); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...ns.DependencyInjection/tests/DI.Specification.Tests/Fakes/ClassInheritingAbstractClass.cs
This file contains hidden or 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. | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection.Specification.Fakes | ||
| { | ||
| public class ClassInheritingAbstractClass : AbstractClass | ||
| { | ||
|
|
||
| } | ||
|
|
||
| public class ClassAlsoInheritingAbstractClass : AbstractClass | ||
| { | ||
|
|
||
| } | ||
|
|
||
| public class ClassInheritingClassInheritingAbstractClass : ClassInheritingAbstractClass | ||
| { | ||
|
|
||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
...ependencyInjection/tests/DI.Specification.Tests/Fakes/ClassWithAbstractClassConstraint.cs
This file contains hidden or 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,14 @@ | ||
| // 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. | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection.Specification.Fakes | ||
| { | ||
| public class ClassWithAbstractClassConstraint<T> : IFakeOpenGenericService<T> | ||
| where T : AbstractClass | ||
| { | ||
| public ClassWithAbstractClassConstraint(T value) => Value = value; | ||
|
|
||
| public T Value { get; } | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...nsions.DependencyInjection/tests/DI.Specification.Tests/Fakes/ClassWithClassConstraint.cs
This file contains hidden or 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,12 @@ | ||
| // 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. | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection.Specification.Fakes | ||
| { | ||
| public class ClassWithClassConstraint<T> : IFakeOpenGenericService<T> | ||
| where T : class | ||
| { | ||
| public T Value { get; } = default; | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
...ns.DependencyInjection/tests/DI.Specification.Tests/Fakes/ClassWithInterfaceConstraint.cs
This file contains hidden or 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.Collections; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection.Specification.Fakes | ||
| { | ||
| public class ClassWithInterfaceConstraint<T> : IFakeOpenGenericService<T> | ||
| where T : IEnumerable | ||
| { | ||
| public ClassWithInterfaceConstraint(T value) => Value = value; | ||
|
|
||
| public T Value { get; } | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...tensions.DependencyInjection/tests/DI.Specification.Tests/Fakes/ClassWithNewConstraint.cs
This file contains hidden or 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,12 @@ | ||
| // 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. | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection.Specification.Fakes | ||
| { | ||
| public class ClassWithNewConstraint<T> : IFakeOpenGenericService<T> | ||
| where T : new() | ||
| { | ||
| public T Value { get; } = new T(); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...xtensions.DependencyInjection/tests/DI.Specification.Tests/Fakes/ClassWithNoConstraint.cs
This file contains hidden or 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,11 @@ | ||
| // 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. | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection.Specification.Fakes | ||
| { | ||
| public class ClassWithNoConstraints<T> : IFakeOpenGenericService<T> | ||
| { | ||
| public T Value { get; } = default; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we skipping these tests? Same questions for the one in Autofac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At one point, AutoFac didn't support constraints on
new. I'm not sure that's relevant though, type constraints the useful bit for services. I'll double check though, it's been a few years since I tried this example when it failed.The others were similar, they all worked with the desired scenarios, but not necessarily all constraints (like
struct). I'll update and retry those.