diff --git a/MediatR.sln b/MediatR.sln
index 59e42981..fe11e313 100644
--- a/MediatR.sln
+++ b/MediatR.sln
@@ -21,6 +21,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Push.ps1 = Push.ps1
README.md = README.md
.github\workflows\release.yml = .github\workflows\release.yml
+ MediatR.snk = MediatR.snk
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR.Benchmarks", "test\MediatR.Benchmarks\MediatR.Benchmarks.csproj", "{1FA62162-F8F1-4CAD-B08E-8DCA603395AD}"
diff --git a/src/MediatR/MediatR.csproj b/src/MediatR/MediatR.csproj
index 2f5a48a4..ef9af93f 100644
--- a/src/MediatR/MediatR.csproj
+++ b/src/MediatR/MediatR.csproj
@@ -30,6 +30,12 @@
+
+
+
+ <_Parameter1>MediatR.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010091986edd141861f402457659cb82b56cf6a0d60b3bd2e5aa4ea73d88afa929d278462d6c4c0e2ecbce21948c15514a310a82e6b2e6beaab6cb14230a03bc026609be59f938423f2490fa0033ae87a982fb4950db77d1a4635e14f7727161e93e5511de766ed8e515efd801464b7820a27fca30a32161485824e442cc5ffecfbe
+
+
diff --git a/src/MediatR/MicrosoftExtensionsDI/ServiceCollectionExtensions.cs b/src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs
similarity index 85%
rename from src/MediatR/MicrosoftExtensionsDI/ServiceCollectionExtensions.cs
rename to src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs
index 3b7b31a1..c6982473 100644
--- a/src/MediatR/MicrosoftExtensionsDI/ServiceCollectionExtensions.cs
+++ b/src/MediatR/MicrosoftExtensionsDI/MediatRServiceCollectionExtensions.cs
@@ -18,7 +18,7 @@ namespace Microsoft.Extensions.DependencyInjection;
/// This does not scan for any instances including and .
/// To register behaviors, use the with the open generic or closed generic types.
///
-public static class ServiceCollectionExtensions
+public static class MediatRServiceCollectionExtensions
{
///
/// Registers handlers and mediator types from the specified assemblies
@@ -63,8 +63,13 @@ internal static void CheckLicense(this IServiceProvider serviceProvider)
{
if (LicenseChecked == false)
{
- var licenseAccessor = serviceProvider.GetRequiredService();
- var licenseValidator = serviceProvider.GetRequiredService();
+ var licenseAccessor = serviceProvider.GetService() ?? new LicenseAccessor(
+ serviceProvider.GetRequiredService(),
+ serviceProvider.GetRequiredService()
+ );
+ var licenseValidator = serviceProvider.GetService()
+ ?? new LicenseValidator(serviceProvider.GetRequiredService());
+
var license = licenseAccessor.Current;
licenseValidator.Validate(license);
}
diff --git a/src/MediatR/Registration/ServiceRegistrar.cs b/src/MediatR/Registration/ServiceRegistrar.cs
index c2056c32..7f62cde6 100644
--- a/src/MediatR/Registration/ServiceRegistrar.cs
+++ b/src/MediatR/Registration/ServiceRegistrar.cs
@@ -391,6 +391,8 @@ public static void AddRequiredServices(IServiceCollection services, MediatRServi
services.TryAdd(new ServiceDescriptor(typeof(IMediator), serviceConfiguration.MediatorImplementationType, serviceConfiguration.Lifetime));
services.TryAdd(new ServiceDescriptor(typeof(ISender), sp => sp.GetRequiredService(), serviceConfiguration.Lifetime));
services.TryAdd(new ServiceDescriptor(typeof(IPublisher), sp => sp.GetRequiredService(), serviceConfiguration.Lifetime));
+
+ MediatRServiceCollectionExtensions.LicenseChecked = false;
services.TryAddSingleton(serviceConfiguration);
services.TryAddSingleton();
diff --git a/test/MediatR.Tests/CreateStreamTests.cs b/test/MediatR.Tests/CreateStreamTests.cs
index 4139b75b..daa6bfd5 100644
--- a/test/MediatR.Tests/CreateStreamTests.cs
+++ b/test/MediatR.Tests/CreateStreamTests.cs
@@ -7,7 +7,6 @@ namespace MediatR.Tests;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Shouldly;
-using Lamar;
using Xunit;
public class CreateStreamTests
@@ -38,15 +37,13 @@ public async Task Should_resolve_main_handler()
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(CreateStreamTests));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IStreamRequestHandler<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IStreamRequestHandler<,>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var response = mediator.CreateStream(new Ping { Message = "Ping" });
int i = 0;
@@ -70,15 +67,13 @@ public async Task Should_resolve_main_handler_via_dynamic_dispatch()
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(CreateStreamTests));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IStreamRequestHandler<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IStreamRequestHandler<,>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
object request = new Ping { Message = "Ping" };
var response = mediator.CreateStream(request);
@@ -103,15 +98,13 @@ public async Task Should_resolve_main_handler_by_specific_interface()
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(CreateStreamTests));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IStreamRequestHandler<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IStreamRequestHandler<,>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var response = mediator.CreateStream(new Ping { Message = "Ping" });
int i = 0;
await foreach (Pong result in response)
@@ -132,10 +125,10 @@ public void Should_raise_execption_on_null_request()
{
var container = TestContainer.Create(cfg =>
{
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
Should.Throw(() => mediator.CreateStream((Ping) null!));
}
@@ -145,10 +138,10 @@ public void Should_raise_execption_on_null_request_via_dynamic_dispatch()
{
var container = TestContainer.Create(cfg =>
{
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
Should.Throw(() => mediator.CreateStream((object) null!));
}
diff --git a/test/MediatR.Tests/ExceptionTests.cs b/test/MediatR.Tests/ExceptionTests.cs
index 7bf81aff..54108f72 100644
--- a/test/MediatR.Tests/ExceptionTests.cs
+++ b/test/MediatR.Tests/ExceptionTests.cs
@@ -5,9 +5,7 @@ namespace MediatR.Tests;
using System;
using System.Threading.Tasks;
using Shouldly;
-using Lamar;
using Xunit;
-using Lamar.IoC;
public class ExceptionTests
{
@@ -73,21 +71,21 @@ public ExceptionTests()
{
var container = TestContainer.Create(cfg =>
{
- cfg.For().Use();
+ cfg.AddTransient();
});
- _mediator = container.GetInstance();
+ _mediator = container.GetRequiredService();
}
[Fact]
public async Task Should_throw_for_send()
{
- await Should.ThrowAsync(async () => await _mediator.Send(new Ping()));
+ await Should.ThrowAsync(async () => await _mediator.Send(new Ping()));
}
[Fact]
public async Task Should_throw_for_void_send()
{
- await Should.ThrowAsync(async () => await _mediator.Send(new VoidPing()));
+ await Should.ThrowAsync(async () => await _mediator.Send(new VoidPing()));
}
[Fact]
@@ -108,13 +106,13 @@ public async Task Should_not_throw_for_publish()
[Fact]
public async Task Should_throw_for_async_send()
{
- await Should.ThrowAsync(async () => await _mediator.Send(new AsyncPing()));
+ await Should.ThrowAsync(async () => await _mediator.Send(new AsyncPing()));
}
[Fact]
public async Task Should_throw_for_async_void_send()
{
- await Should.ThrowAsync(async () => await _mediator.Send(new AsyncVoidPing()));
+ await Should.ThrowAsync(async () => await _mediator.Send(new AsyncVoidPing()));
}
[Fact]
@@ -139,14 +137,12 @@ public async Task Should_throw_argument_exception_for_send_when_request_is_null(
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(NullPing));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<,>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
NullPing request = null!;
@@ -160,14 +156,12 @@ public async Task Should_throw_argument_exception_for_void_send_when_request_is_
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(VoidNullPing));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<,>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
VoidNullPing request = null!;
@@ -181,14 +175,12 @@ public async Task Should_throw_argument_exception_for_publish_when_request_is_nu
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(NullPinged));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<,>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
NullPinged notification = null!;
@@ -202,14 +194,12 @@ public async Task Should_throw_argument_exception_for_publish_when_request_is_nu
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(NullPinged));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<,>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
object notification = null!;
@@ -223,14 +213,12 @@ public async Task Should_throw_argument_exception_for_publish_when_request_is_no
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(NullPinged));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<,>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
object notification = "totally not notification";
@@ -257,15 +245,13 @@ public async Task Should_throw_exception_for_non_generic_send_when_exception_occ
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(NullPinged));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
- scanner.AddAllTypesOf(typeof(IRequestHandler<>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<,>))).AsImplementedInterfaces()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
object pingException = new PingException();
@@ -279,14 +265,12 @@ public async Task Should_throw_exception_for_non_request_send()
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(NullPinged));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<,>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
object nonRequest = new NonRequest();
@@ -306,15 +290,13 @@ public async Task Should_throw_exception_for_generic_send_when_exception_occurs(
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(NullPinged));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
- scanner.AddAllTypesOf(typeof(IRequestHandler<>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<,>))).AsImplementedInterfaces()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
PingException pingException = new PingException();
diff --git a/test/MediatR.Tests/GenericTypeConstraintsTests.cs b/test/MediatR.Tests/GenericTypeConstraintsTests.cs
index 3d3da79b..3846faa4 100644
--- a/test/MediatR.Tests/GenericTypeConstraintsTests.cs
+++ b/test/MediatR.Tests/GenericTypeConstraintsTests.cs
@@ -6,7 +6,6 @@ namespace MediatR.Tests;
using System;
using System.Linq;
using Shouldly;
-using Lamar;
using System.Threading.Tasks;
using Xunit;
@@ -93,17 +92,14 @@ public GenericTypeConstraintsTests()
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(GenericTypeConstraintsTests));
- scanner.IncludeNamespaceContainingType();
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
- scanner.AddAllTypesOf(typeof(IRequestHandler<>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<,>))).AsImplementedInterfaces()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<>))).AsImplementedInterfaces();
});
- cfg.For().Use();
+ cfg.AddTransient();
});
- _mediator = container.GetInstance();
+ _mediator = container.GetRequiredService();
}
[Fact]
diff --git a/test/MediatR.Tests/MediatR.Tests.csproj b/test/MediatR.Tests/MediatR.Tests.csproj
index 6f405ac3..4ac61f57 100644
--- a/test/MediatR.Tests/MediatR.Tests.csproj
+++ b/test/MediatR.Tests/MediatR.Tests.csproj
@@ -6,23 +6,20 @@
enable
$(NoWarn);CS8002;
false
+ true
+ ..\..\MediatR.snk
-
-
-
-
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
diff --git a/test/MediatR.Tests/MicrosoftExtensionsDI/PipelineTests.cs b/test/MediatR.Tests/MicrosoftExtensionsDI/PipelineTests.cs
index f8c04223..fabc0ab1 100644
--- a/test/MediatR.Tests/MicrosoftExtensionsDI/PipelineTests.cs
+++ b/test/MediatR.Tests/MicrosoftExtensionsDI/PipelineTests.cs
@@ -395,6 +395,7 @@ public async Task Should_wrap_with_behavior()
var output = new Logger();
IServiceCollection services = new ServiceCollection();
services.AddSingleton(output);
+ services.AddFakeLogging();
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(typeof(Ping).Assembly);
@@ -425,6 +426,7 @@ public async Task Should_wrap_generics_with_behavior()
var output = new Logger();
IServiceCollection services = new ServiceCollection();
services.AddSingleton(output);
+ services.AddFakeLogging();
services.AddMediatR(cfg =>
{
// Call these registration methods multiple times to prove we don't register a service if it is already registered
@@ -459,6 +461,7 @@ public async Task Should_register_pre_and_post_processors()
var output = new Logger();
IServiceCollection services = new ServiceCollection();
services.AddSingleton(output);
+ services.AddFakeLogging();
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(typeof(Ping).Assembly);
@@ -498,6 +501,7 @@ public async Task Should_pick_up_specific_exception_behaviors()
{
var output = new Logger();
IServiceCollection services = new ServiceCollection();
+ services.AddFakeLogging();
services.AddSingleton(output);
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Ping).Assembly));
var provider = services.BuildServiceProvider();
@@ -534,6 +538,7 @@ public void Should_handle_exceptions_from_behaviors()
var output = new Logger();
IServiceCollection services = new ServiceCollection();
services.AddSingleton(output);
+ services.AddFakeLogging();
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(typeof(Ping).Assembly);
@@ -554,6 +559,7 @@ public void Should_pick_up_exception_actions()
{
var output = new Logger();
IServiceCollection services = new ServiceCollection();
+ services.AddFakeLogging();
services.AddSingleton(output);
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Ping).Assembly));
var provider = services.BuildServiceProvider();
@@ -572,6 +578,7 @@ public async Task Should_handle_constrained_generics()
var output = new Logger();
IServiceCollection services = new ServiceCollection();
services.AddSingleton(output);
+ services.AddFakeLogging();
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(typeof(Ping).Assembly);
diff --git a/test/MediatR.Tests/MicrosoftExtensionsDI/StreamPipelineTests.cs b/test/MediatR.Tests/MicrosoftExtensionsDI/StreamPipelineTests.cs
index 9ca8fd1b..b0aa8318 100644
--- a/test/MediatR.Tests/MicrosoftExtensionsDI/StreamPipelineTests.cs
+++ b/test/MediatR.Tests/MicrosoftExtensionsDI/StreamPipelineTests.cs
@@ -60,6 +60,7 @@ public async Task Should_wrap_with_behavior()
{
var output = new Logger();
IServiceCollection services = new ServiceCollection();
+ services.AddFakeLogging();
services.AddSingleton(output);
services.AddTransient, OuterBehavior>();
services.AddTransient, InnerBehavior>();
diff --git a/test/MediatR.Tests/NotificationPublisherTests.cs b/test/MediatR.Tests/NotificationPublisherTests.cs
index a355a896..a41e7891 100644
--- a/test/MediatR.Tests/NotificationPublisherTests.cs
+++ b/test/MediatR.Tests/NotificationPublisherTests.cs
@@ -53,6 +53,7 @@ public async Task Should_handle_sequentially_by_default()
var sequentialElapsed = timer.ElapsedMilliseconds;
services = new ServiceCollection();
+ services.AddFakeLogging();
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssemblyContaining();
diff --git a/test/MediatR.Tests/Pipeline/RequestExceptionActionTests.cs b/test/MediatR.Tests/Pipeline/RequestExceptionActionTests.cs
index 629859d7..5876d2b1 100644
--- a/test/MediatR.Tests/Pipeline/RequestExceptionActionTests.cs
+++ b/test/MediatR.Tests/Pipeline/RequestExceptionActionTests.cs
@@ -1,5 +1,4 @@
using MediatR.Pipeline;
-using Lamar;
namespace MediatR.Tests.Pipeline;
@@ -97,15 +96,15 @@ public async Task Should_run_all_exception_actions_that_match_base_type()
var container = TestContainer.Create(cfg =>
{
- cfg.For>().Use();
- cfg.For>().Use(_ => pingExceptionAction);
- cfg.For>().Use(_ => pingPongExceptionAction);
- cfg.For>().Use(_ => pongExceptionAction);
- cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestExceptionActionProcessorBehavior<,>));
- cfg.For().Use();
+ cfg.AddTransient, PingHandler>();
+ cfg.AddTransient>(_ => pingExceptionAction);
+ cfg.AddTransient>(_ => pingPongExceptionAction);
+ cfg.AddTransient>(_ => pongExceptionAction);
+ cfg.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestExceptionActionProcessorBehavior<,>));
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var request = new Ping { Message = "Ping!" };
await Assert.ThrowsAsync(() => mediator.Send(request));
@@ -121,13 +120,13 @@ public async Task Should_run_matching_exception_actions_only_once()
var genericExceptionAction = new GenericExceptionAction();
var container = TestContainer.Create(cfg =>
{
- cfg.For>().Use();
- cfg.For>().Use(_ => genericExceptionAction);
- cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestExceptionActionProcessorBehavior<,>));
- cfg.For().Use();
+ cfg.AddTransient, PingHandler>();
+ cfg.AddTransient>(_ => genericExceptionAction);
+ cfg.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestExceptionActionProcessorBehavior<,>));
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var request = new Ping { Message = "Ping!" };
await Assert.ThrowsAsync(() => mediator.Send(request));
diff --git a/test/MediatR.Tests/Pipeline/RequestExceptionHandlerTests.cs b/test/MediatR.Tests/Pipeline/RequestExceptionHandlerTests.cs
index aef3c346..3b7409f9 100644
--- a/test/MediatR.Tests/Pipeline/RequestExceptionHandlerTests.cs
+++ b/test/MediatR.Tests/Pipeline/RequestExceptionHandlerTests.cs
@@ -5,7 +5,6 @@ namespace MediatR.Tests.Pipeline;
using System.Threading.Tasks;
using MediatR.Pipeline;
using Shouldly;
-using Lamar;
using Xunit;
public class RequestExceptionHandlerTests
@@ -89,14 +88,14 @@ public async Task Should_run_exception_handler_and_allow_for_exception_not_to_th
{
var container = TestContainer.Create(cfg =>
{
- cfg.For>().Use();
- cfg.For>().Use();
- cfg.For>().Use();
- cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestExceptionProcessorBehavior<,>));
- cfg.For().Use();
+ cfg.AddTransient, PingHandler>();
+ cfg.AddTransient, PingPongExceptionHandler>();
+ cfg.AddTransient, PingPongExceptionHandlerForType>();
+ cfg.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestExceptionProcessorBehavior<,>));
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var response = await mediator.Send(new Ping { Message = "Ping" });
@@ -108,13 +107,13 @@ public async Task Should_run_exception_handler_and_allow_for_exception_to_be_sti
{
var container = TestContainer.Create(cfg =>
{
- cfg.For>().Use();
- cfg.For>().Use();
- cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestExceptionProcessorBehavior<,>));
- cfg.For().Use();
+ cfg.AddTransient, PingHandler>();
+ cfg.AddTransient, PingPongExceptionHandlerNotHandled>();
+ cfg.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestExceptionProcessorBehavior<,>));
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var request = new Ping { Message = "Ping" };
await Should.ThrowAsync(async () =>
@@ -130,13 +129,13 @@ public async Task Should_run_exception_handler_and_unwrap_expections_thrown_in_t
{
var container = TestContainer.Create(cfg =>
{
- cfg.For>().Use();
- cfg.For>().Use();
- cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestExceptionProcessorBehavior<,>));
- cfg.For().Use();
+ cfg.AddTransient, PingHandler>();
+ cfg.AddTransient, PingPongThrowingExceptionHandler>();
+ cfg.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestExceptionProcessorBehavior<,>));
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var request = new Ping { Message = "Ping" };
await Should.ThrowAsync(async () =>
@@ -151,13 +150,13 @@ public async Task Should_run_matching_exception_handlers_only_once()
var genericPingExceptionHandler = new GenericPingExceptionHandler();
var container = TestContainer.Create(cfg =>
{
- cfg.For>().Use();
- cfg.For>().Use(genericPingExceptionHandler);
- cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestExceptionProcessorBehavior<,>));
- cfg.For().Use();
+ cfg.AddTransient, PingHandler>();
+ cfg.AddSingleton>(genericPingExceptionHandler);
+ cfg.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestExceptionProcessorBehavior<,>));
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var request = new Ping { Message = "Ping" };
await Should.ThrowAsync(async () =>
diff --git a/test/MediatR.Tests/Pipeline/RequestPostProcessorTests.cs b/test/MediatR.Tests/Pipeline/RequestPostProcessorTests.cs
index 73a854e5..3f2f9f6c 100644
--- a/test/MediatR.Tests/Pipeline/RequestPostProcessorTests.cs
+++ b/test/MediatR.Tests/Pipeline/RequestPostProcessorTests.cs
@@ -5,7 +5,6 @@ namespace MediatR.Tests.Pipeline;
using System.Threading.Tasks;
using MediatR.Pipeline;
using Shouldly;
-using Lamar;
using Xunit;
public class RequestPostProcessorTests
@@ -45,17 +44,14 @@ public async Task Should_run_postprocessors()
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(PublishTests));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
- scanner.AddAllTypesOf(typeof(IRequestPostProcessor<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf()).AsImplementedInterfaces();
});
- cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestPostProcessorBehavior<,>));
- cfg.For().Use();
+ cfg.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var response = await mediator.Send(new Ping { Message = "Ping" });
diff --git a/test/MediatR.Tests/Pipeline/RequestPreProcessorTests.cs b/test/MediatR.Tests/Pipeline/RequestPreProcessorTests.cs
index a868b60f..11e5b604 100644
--- a/test/MediatR.Tests/Pipeline/RequestPreProcessorTests.cs
+++ b/test/MediatR.Tests/Pipeline/RequestPreProcessorTests.cs
@@ -5,7 +5,6 @@ namespace MediatR.Tests.Pipeline;
using System.Threading.Tasks;
using MediatR.Pipeline;
using Shouldly;
-using Lamar;
using Xunit;
public class RequestPreProcessorTests
@@ -45,17 +44,14 @@ public async Task Should_run_preprocessors()
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(PublishTests));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
- scanner.AddAllTypesOf(typeof(IRequestPreProcessor<>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf()).AsImplementedInterfaces();
});
- cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(RequestPreProcessorBehavior<,>));
- cfg.For().Use();
+ cfg.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>));
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var response = await mediator.Send(new Ping { Message = "Ping" });
diff --git a/test/MediatR.Tests/Pipeline/Streams/StreamPipelineBehaviorTests.cs b/test/MediatR.Tests/Pipeline/Streams/StreamPipelineBehaviorTests.cs
index 3145f320..8562284a 100644
--- a/test/MediatR.Tests/Pipeline/Streams/StreamPipelineBehaviorTests.cs
+++ b/test/MediatR.Tests/Pipeline/Streams/StreamPipelineBehaviorTests.cs
@@ -5,7 +5,6 @@
namespace MediatR.Tests.Pipeline.Streams;
using Shouldly;
-using Lamar;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
diff --git a/test/MediatR.Tests/PipelineTests.cs b/test/MediatR.Tests/PipelineTests.cs
index 33a5b1b9..79983886 100644
--- a/test/MediatR.Tests/PipelineTests.cs
+++ b/test/MediatR.Tests/PipelineTests.cs
@@ -5,7 +5,6 @@ namespace MediatR.Tests;
using System.Collections.Generic;
using System.Threading.Tasks;
using Shouldly;
-using Lamar;
using Xunit;
public class PipelineTests
@@ -248,18 +247,16 @@ public async Task Should_wrap_with_behavior()
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(PublishTests));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<,>))).AsImplementedInterfaces();
});
- cfg.For().Use(output);
- cfg.For>().Add();
- cfg.For>().Add();
- cfg.For().Use();
+ cfg.AddSingleton(output);
+ cfg.AddTransient, OuterBehavior>();
+ cfg.AddTransient, InnerBehavior>();
+ cfg.AddTransient();
});
- var mediator = container.GetInstance();
+ var mediator = container.GetRequiredService();
var response = await mediator.Send(new Ping { Message = "Ping" });
@@ -283,18 +280,16 @@ public async Task Should_wrap_void_with_behavior()
{
cfg.Scan(scanner =>
{
- scanner.AssemblyContainingType(typeof(PublishTests));
- scanner.IncludeNamespaceContainingType();
- scanner.WithDefaultConventions();
- scanner.AddAllTypesOf(typeof(IRequestHandler<>));
+ scanner.FromAssemblyOf()
+ .AddClasses(t => t.InNamespaceOf().AssignableTo(typeof(IRequestHandler<>))).AsImplementedInterfaces();
});
- cfg.For().Use(output);
- cfg.For