Browse Source

Merge pull request #25362 from abpframework/auto-merge/rel-10-3/4538

Merge branch rel-10.4 with rel-10.3
pull/25363/head
Volosoft Agent 2 weeks ago
committed by GitHub
parent
commit
76efb01c69
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/InMemoryDynamicBackgroundWorker.cs
  2. 37
      framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundWorkers/InMemoryDynamicBackgroundWorker_Registration_Tests.cs

2
framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/InMemoryDynamicBackgroundWorker.cs

@ -1,10 +1,12 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Threading;
namespace Volo.Abp.BackgroundWorkers;
[DisableConventionalRegistration]
public class InMemoryDynamicBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
{
public string WorkerName { get; }

37
framework/test/Volo.Abp.BackgroundJobs.Tests/Volo/Abp/BackgroundWorkers/InMemoryDynamicBackgroundWorker_Registration_Tests.cs

@ -0,0 +1,37 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
namespace Volo.Abp.BackgroundWorkers;
public class InMemoryDynamicBackgroundWorker_Registration_Tests
{
// Reproduces the original failure: ASP.NET Core in Development enables ValidateOnBuild,
// and InMemoryDynamicBackgroundWorker has a `string workerName` constructor parameter
// that DI cannot resolve. Without [DisableConventionalRegistration] this throws:
// Unable to resolve service for type 'System.String' while attempting to activate
// 'Volo.Abp.BackgroundWorkers.InMemoryDynamicBackgroundWorker'.
[Fact]
public async Task BuildServiceProvider_With_ValidateOnBuild_Should_Not_Throw()
{
using var application = await AbpApplicationFactory.CreateAsync<AbpBackgroundWorkersModule>();
var act = () => application.Services.BuildServiceProvider(
new ServiceProviderOptions { ValidateOnBuild = true });
act.ShouldNotThrow();
}
// Verifies the fix: InMemoryDynamicBackgroundWorker is created on demand by
// DefaultDynamicBackgroundWorkerManager (`new InMemoryDynamicBackgroundWorker(...)`)
// and must stay out of the conventional registration loop.
[Fact]
public async Task InMemoryDynamicBackgroundWorker_Should_Not_Be_Registered_As_Service()
{
using var application = await AbpApplicationFactory.CreateAsync<AbpBackgroundWorkersModule>();
application.Services.ShouldNotContain(d => d.ServiceType == typeof(InMemoryDynamicBackgroundWorker));
}
}
Loading…
Cancel
Save