|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System.Linq; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Reflection; |
|
|
|
using Microsoft.AspNetCore.Mvc.ApplicationParts; |
|
|
|
|
|
|
|
@ -8,13 +9,23 @@ namespace Microsoft.Extensions.DependencyInjection |
|
|
|
{ |
|
|
|
public static void AddApplicationPartIfNotExists(this IMvcBuilder mvcBuilder, Assembly assembly) |
|
|
|
{ |
|
|
|
if (mvcBuilder.PartManager.ApplicationParts.Any( |
|
|
|
mvcBuilder.PartManager.ApplicationParts.AddIfNotContains(assembly); |
|
|
|
} |
|
|
|
|
|
|
|
public static void AddApplicationPartIfNotExists(this IMvcCoreBuilder mvcCoreBuilder, Assembly assembly) |
|
|
|
{ |
|
|
|
mvcCoreBuilder.PartManager.ApplicationParts.AddIfNotContains(assembly); |
|
|
|
} |
|
|
|
|
|
|
|
public static void AddIfNotContains(this IList<ApplicationPart> applicationParts, Assembly assembly) |
|
|
|
{ |
|
|
|
if (applicationParts.Any( |
|
|
|
p => p is AssemblyPart assemblyPart && assemblyPart.Assembly == assembly)) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(assembly)); |
|
|
|
applicationParts.Add(new AssemblyPart(assembly)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|