-
Notifications
You must be signed in to change notification settings - Fork 314
Conversation
@@ -152,7 +150,7 @@ public static class ServiceCollectionDescriptorExtensions | |||
throw new ArgumentNullException(nameof(implementationType)); | |||
} | |||
|
|||
var descriptor = ServiceDescriptor.Transient(service, implementationType); | |||
var descriptor = TypeServiceDescriptor.Transient(service, implementationType); |
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.
I think you should leave these factory methods on the ServiceDescriptor
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public class EnumerableServiceDescriptor: ServiceDescriptor |
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.
👏
From #416 (comment):
BTW, why are these properties on same type instead of different types?
How do we get to these types from the collection? Just enumerate and switch on type? Since this is a breaking change, does this mean 2,0 is coming pretty soon after 1.1? 😄
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.
Yes you have to downcast. We're willing a limited set of APIs for 1.1. This is one of them.
@@ -123,7 +124,7 @@ public void TransientServiceCanBeResolvedFromScope() | |||
} | |||
|
|||
[Fact] | |||
public void SingleServiceCanBeIEnumerableResolved() | |||
public void NonEnumerablServiceCanNotBeIEnumerableResolved() |
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.
Typo: "Enumerabl"
I'm wondering if it's really required to differentiate between AddOrdered and AddEnumerable?! Since AddOrdered can also be resolved as IEnumerable, why not exclusively use this implementation for all enumerables? It wouldn't have any disadvantage if all enumerables were ordered and always resolved in order, would it? Will |
If there were only one ordered version, the name should still be AddEnumerable though IMO |
@cwe1ss we are trying to decrease framework reliance ordered enumerable. Also most dependency injection frameworks support IEnumerable natively which should give better performance and feature set then current Ordered implementation does (uses ActivatorUtilities to create instances of type). |
@@ -0,0 +1,19 @@ | |||
using System; |
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.
nit: missing (c)
@@ -150,4 +150,8 @@ | |||
<data name="DirectScopedResolvedFromRootException" xml:space="preserve"> | |||
<value>Cannot resolve {1} service '{0}' from root provider.</value> | |||
</data> | |||
<data name="UnsupportedServiceDescriptorType" xml:space="preserve"> |
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.
Remove from this resx
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public class ServiceCollectionOrderedServiceExtensionsTest |
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.
Shouldn't these tests be added to the SpecificationTests to replace RegistrationOrderIsPreservedWhenServicesAreIEnumerableResolved
? In theory, containers should get this for "free" once they Populate
methods are updated to deal with the new factoring of the existing service descriptors while ignoring the ordered descriptors. Still it would be good to verify this.
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.
Uhhhh, that shouldn't be in the spec tests.
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.
It's free tests for container authors in case they decides to re-implement IOrdered
.
@@ -173,7 +68,7 @@ public static ServiceDescriptor Transient<TService>(Func<IServiceProvider, TServ | |||
return Describe(typeof(TService), implementationFactory, ServiceLifetime.Transient); | |||
} | |||
|
|||
public static ServiceDescriptor Transient(Type service, | |||
public static FactoryServiceDescriptor Transient(Type service, |
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.
Indentation.
public class FactoryServiceDescriptor : ServiceDescriptor | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="ServiceDescriptor"/> with the specified <paramref name="factory"/>. |
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.
Initializes a new instance of FactoryServiceDescriptor
ServiceLifetime lifetime) | ||
: base(serviceType, lifetime) | ||
{ | ||
if (serviceType == null) |
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.
Is there a reason you're checking this in some descriptors, but not in EnumerableServiceDescriptor
and OrderedEnumerableServiceDescriptor
? Shouldn't thisnull
check just be moved up to the base class? I don't believe you ever want ServiceType
to be null
....
6435bf6
to
ea30315
Compare
@davidfowl @halter73