Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit 5adc6b2

Browse files
author
Toby Henderson
committed
Have to register the Command Processor as scoped #14
1 parent aa0dba3 commit 5adc6b2

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Tests/AssemblyResolutionHandlerLifetimeScopedAndMapperLifetimeSingletonTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void ShouldHaveRegistered12Correctly()
4141
[Fact]
4242
public void ShouldHaveCommandProcessorRegisteredCorrectly()
4343
{
44-
TestRegistration(typeof(IAmACommandProcessor), ServiceLifetime.Singleton);
44+
TestRegistration(typeof(IAmACommandProcessor), ServiceLifetime.Scoped);
4545
}
4646

4747
[Fact]

src/Paramore.Brighter.Extensions.DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public static IBrighterHandlerBuilder AddBrighter(this IServiceCollection servic
1717
var subscriberRegistry = new ServiceCollectionSubscriberRegistry(services, options.HandlerLifetime);
1818
services.AddSingleton<ServiceCollectionSubscriberRegistry>(subscriberRegistry);
1919

20-
services.AddSingleton<IAmACommandProcessor>(BuildCommandProcessor);
20+
if (options.HandlerLifetime == ServiceLifetime.Scoped)
21+
services.AddScoped<IAmACommandProcessor>(BuildCommandProcessor);
22+
else
23+
services.AddSingleton<IAmACommandProcessor>(BuildCommandProcessor);
2124

2225
return new ServiceCollectionBrighterBuilder(services, subscriberRegistry);
2326
}

src/Paramore.Brighter.ServiceActivator.Extensions.DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public static IServiceActivatorBuilder AddServiceActivator(
2020
var subscriberRegistry = new ServiceCollectionSubscriberRegistry(services, options.HandlerLifetime);
2121
services.AddSingleton<ServiceCollectionSubscriberRegistry>(subscriberRegistry);
2222

23-
services.AddSingleton<IAmACommandProcessor>(BuildCommandProcessor);
23+
if (options.HandlerLifetime == ServiceLifetime.Scoped)
24+
services.AddScoped<IAmACommandProcessor>(BuildCommandProcessor);
25+
else
26+
services.AddSingleton<IAmACommandProcessor>(BuildCommandProcessor);
2427

2528
var mapperRegistry = new ServiceCollectionMessageMapperRegistry(services, options.MapperLifetime);
2629
services.AddSingleton<ServiceCollectionMessageMapperRegistry>(mapperRegistry);

0 commit comments

Comments
 (0)