Skip to content
This repository was archived by the owner on Nov 2, 2018. It is now read-only.

[WIP] Future Concept #437

Closed
wants to merge 22 commits into from
Closed

[WIP] Future Concept #437

wants to merge 22 commits into from

Conversation

pakrym
Copy link
Contributor

@pakrym pakrym commented Jul 27, 2016

@@ -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);
Copy link
Member

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
Copy link
Contributor

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? 😄

Copy link
Member

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()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "Enumerabl"

@cwe1ss
Copy link

cwe1ss commented Jul 28, 2016

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 AddOrdered also support ways to add items somewhere else than at the end? (e.g. at the beginning or somewhere in the middle by specifying an index, ...)? Wouldn't this be required for IStartupFilter etc? Especially being able to add something at the beginning seems really important to me.

@cwe1ss
Copy link

cwe1ss commented Jul 28, 2016

If there were only one ordered version, the name should still be AddEnumerable though IMO

@pakrym
Copy link
Contributor Author

pakrym commented Jul 28, 2016

@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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing (c)

@pakrym pakrym force-pushed the pakrym/di-future branch from d19f6c0 to 11543ff Compare July 28, 2016 22:25
@pakrym pakrym force-pushed the pakrym/di-future branch from 11543ff to cdc4479 Compare July 28, 2016 22:27
@@ -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">
Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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,
Copy link
Contributor

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"/>.
Copy link
Member

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)
Copy link
Contributor

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....

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants