Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1244222

Browse files
authoredNov 25, 2024··
Allow constructor injection of an array of a registered servicetype (#39)
1 parent 1f84934 commit 1244222

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎nanoFramework.DependencyInjection/Microsoft/Extensions/DependencyInjection/ServiceProviderEngine.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ private object Resolve(Type implementationType)
211211
}
212212
else
213213
{
214-
var service = GetService(parameterType);
214+
var service = parameterType.IsArray ?
215+
GetServiceObjects(parameterType.GetElementType(), null) :
216+
GetService(parameterType);
215217

216218
if (service == null)
217219
{
@@ -326,6 +328,11 @@ private static object GetResolvableDefault(Type type)
326328
/// <returns>true if the specified service is a available, false if it is not.</returns>
327329
internal bool IsService(Type serviceType)
328330
{
331+
if (serviceType.IsArray)
332+
{
333+
serviceType = serviceType.GetElementType();
334+
}
335+
329336
foreach (ServiceDescriptor descriptor in Services)
330337
{
331338
if (descriptor.ServiceType == serviceType)

0 commit comments

Comments
 (0)
Please sign in to comment.