Browse Source

Do not add duplicate assemblies.

pull/10495/head
maliming 4 years ago
parent
commit
902583ec06
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 10
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs
  2. 41
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/AutoServiceRegistration_Tests.cs

10
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -136,6 +137,8 @@ namespace Volo.Abp
}
}
var assemblies = new HashSet<Assembly>();
//ConfigureServices
foreach (var module in Modules)
{
@ -143,7 +146,12 @@ namespace Volo.Abp
{
if (!abpModule.SkipAutoServiceRegistration)
{
Services.AddAssembly(module.Type.Assembly);
var assembly = module.Type.Assembly;
if (!assemblies.Contains(assembly))
{
Services.AddAssembly(assembly);
assemblies.Add(assembly);
}
}
}

41
framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/AutoServiceRegistration_Tests.cs

@ -0,0 +1,41 @@
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Modularity;
using Xunit;
namespace Volo.Abp.DependencyInjection
{
public class AutoServiceRegistration_Tests
{
[Fact]
public void AutoServiceRegistration_Should_Not_Duplicate_Test()
{
using (var application = AbpApplicationFactory.Create<TestModule>())
{
//Act
application.Initialize();
//Assert
var services = application.ServiceProvider.GetServices<TestService>().ToList();
services.Count.ShouldBe(1);
}
}
}
[DependsOn(typeof(TestDependedModule))]
public class TestModule : AbpModule
{
}
public class TestDependedModule : AbpModule
{
}
public class TestService : ITransientDependency
{
}
}
Loading…
Cancel
Save