This repository was archived by the owner on Nov 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 314
[WIP] Future Concept #437
Closed
Closed
[WIP] Future Concept #437
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d1ea6fe
EnumerableServiceDescriptor
pakrym 6932574
Ordered
pakrym 116ad6f
Move files around
pakrym ab2db0b
Seperate them all
pakrym 05c8e95
Move factory methods back, more tests
pakrym cdc4479
Split ordered into seperate package
pakrym d437a80
Remove error message from resources
pakrym e698d1b
Remove GetImplementationType from descriptor
pakrym 2804dbf
Rename OrderedServiceDescriptorHolder
pakrym edbc2c3
Revert "Remove error message from resources"
pakrym 7b97da6
Add lost files
pakrym 1d110fe
A bit more renames
pakrym 228193c
Merget ordered tests with spec tests
pakrym 79a4c06
PR comments and make AddOrdered not resolve as IEnumerable
pakrym 43d44f8
Use OfType<> to search for descriptor
pakrym b46a2f0
More PR feedback
pakrym ea30315
Add support for scoped ordered services
pakrym 1d46155
Add IServiceEditor move extension methods to use it and implement Ord…
pakrym 7ec4551
Fix overdisposing of singletons
pakrym 0ed8e05
Move extension methods around
pakrym 8b15017
Move some tests out of specs project
pakrym 6f230a6
Unity and Ninject
pakrym 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
17 changes: 17 additions & 0 deletions
17
src/Microsoft.Extensions.DependencyInjection.Abstractions/EnumerableServiceDescriptor.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,17 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public class EnumerableServiceDescriptor : ServiceDescriptor | ||
{ | ||
public EnumerableServiceDescriptor(Type serviceType) : base(serviceType, ServiceLifetime.Transient) | ||
{ | ||
} | ||
|
||
public IList<ServiceDescriptor> Descriptors { get; } = new List<ServiceDescriptor>(); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/Microsoft.Extensions.DependencyInjection.Abstractions/FactoryServiceDescriptor.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,38 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
[DebuggerDisplay("Lifetime = {Lifetime}, ServiceType = {ServiceType}, ImplementationFactory = {ImplementationFactory}")] | ||
public class FactoryServiceDescriptor : ServiceDescriptor | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="FactoryServiceDescriptor"/> with the specified <paramref name="factory"/>. | ||
/// </summary> | ||
/// <param name="serviceType">The <see cref="Type"/> of the service.</param> | ||
/// <param name="factory">A factory used for creating service instances.</param> | ||
/// <param name="lifetime">The <see cref="ServiceLifetime"/> of the service.</param> | ||
public FactoryServiceDescriptor(Type serviceType, Func<IServiceProvider, object> factory, | ||
ServiceLifetime lifetime) | ||
: base(serviceType, lifetime) | ||
{ | ||
if (serviceType == null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
{ | ||
throw new ArgumentNullException(nameof(serviceType)); | ||
} | ||
|
||
if (factory == null) | ||
{ | ||
throw new ArgumentNullException(nameof(factory)); | ||
} | ||
|
||
ImplementationFactory = factory; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public Func<IServiceProvider, object> ImplementationFactory { get; } | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
src/Microsoft.Extensions.DependencyInjection.Abstractions/InstanceServiceDescriptor.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,37 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
[DebuggerDisplay("Lifetime = {Lifetime}, ServiceType = {ServiceType}, ImplementationInstance = {ImplementationInstance}")] | ||
public class InstanceServiceDescriptor : ServiceDescriptor | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="InstanceServiceDescriptor"/> with the specified <paramref name="instance"/> | ||
/// as a <see cref="ServiceLifetime.Singleton"/>. | ||
/// </summary> | ||
/// <param name="serviceType">The <see cref="Type"/> of the service.</param> | ||
/// <param name="instance">The instance implementing the service.</param> | ||
public InstanceServiceDescriptor(Type serviceType, object instance) | ||
: base(serviceType, ServiceLifetime.Singleton) | ||
{ | ||
if (serviceType == null) | ||
{ | ||
throw new ArgumentNullException(nameof(serviceType)); | ||
} | ||
|
||
if (instance == null) | ||
{ | ||
throw new ArgumentNullException(nameof(instance)); | ||
} | ||
|
||
ImplementationInstance = instance; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public object ImplementationInstance { get; } | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...soft.Extensions.DependencyInjection.Abstractions/ServiceCollectionEnumerableExtensions.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,42 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using Microsoft.Extensions.DependencyInjection.Abstractions; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class ServiceCollectionEnumerableExtensions | ||
{ | ||
public static IServicesEditor<TService> AddEnumerable<TService>(this IServiceCollection services) | ||
where TService : class | ||
{ | ||
return new ServiceEditor<TService>(GetEnumerableDescriptor(services, typeof(TService)).Descriptors); | ||
} | ||
|
||
public static IServicesEditor AddEnumerable(this IServiceCollection services, Type serviceType) | ||
{ | ||
return new ServiceEditor<object>(GetEnumerableDescriptor(services, serviceType).Descriptors, serviceType); | ||
} | ||
|
||
private static EnumerableServiceDescriptor GetEnumerableDescriptor( | ||
this IServiceCollection collection, | ||
Type serviceType) | ||
{ | ||
var descriptor = (EnumerableServiceDescriptor) | ||
collection.FirstOrDefault(d => | ||
d.GetType() == typeof(EnumerableServiceDescriptor) && | ||
d.ServiceType == serviceType); | ||
if (descriptor == null) | ||
{ | ||
descriptor = new EnumerableServiceDescriptor(serviceType); | ||
collection.Add(descriptor); | ||
} | ||
return descriptor; | ||
} | ||
} | ||
} |
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
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.
nit: missing (c)