Browse Source

Use ApplicationParts.AddIfNotContains for the AbpAspNetCoreMvcModule

pull/4016/head
Halil İbrahim Kalkan 6 years ago
parent
commit
6944d7836d
  1. 17
      framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs
  2. 9
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs

17
framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs

@ -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));
}
}
}

9
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs

@ -161,7 +161,7 @@ namespace Volo.Abp.AspNetCore.Mvc
var application = context.Services.GetSingletonInstance<IAbpApplication>();
partManager.FeatureProviders.Add(new AbpConventionalControllerFeatureProvider(application));
partManager.ApplicationParts.Add(new AssemblyPart(typeof(AbpAspNetCoreMvcModule).Assembly));
partManager.ApplicationParts.AddIfNotContains(typeof(AbpAspNetCoreMvcModule).Assembly);
Configure<MvcOptions>(mvcOptions =>
{
@ -220,12 +220,7 @@ namespace Volo.Abp.AspNetCore.Mvc
{
foreach (var moduleAssembly in moduleAssemblies)
{
if (partManager.ApplicationParts.OfType<AssemblyPart>().Any(p => p.Assembly == moduleAssembly))
{
continue;
}
partManager.ApplicationParts.Add(new AssemblyPart(moduleAssembly));
partManager.ApplicationParts.AddIfNotContains(moduleAssembly);
}
}
}

Loading…
Cancel
Save