Skip to content

Commit b8b9084

Browse files
committed
refactor(aspnetcore): rename AddExceptionless to AddExceptionlessExceptionHandler
Avoids ambiguity with the IServiceCollection.AddExceptionless() overload from Exceptionless.Extensions.Hosting (which has a default parameter). The new name precisely describes what the method does: registers the ExceptionlessExceptionHandler as an IExceptionHandler. Also adds a test verifying that the parameterless AddExceptionless() resolves to the Hosting overload and does not register IExceptionHandler.
1 parent e11b481 commit b8b9084

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

samples/Exceptionless.SampleAspNetCore/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// builder.AddExceptionless("API_KEY_HERE");
1919

2020
// Adds ASP.NET Core request/unhandled exception hooks and standard exception handling services.
21-
builder.Services.AddExceptionless();
21+
builder.Services.AddExceptionlessExceptionHandler();
2222
builder.Services.AddProblemDetails();
2323

2424
// This is normal ASP.NET Core code.

src/Platforms/Exceptionless.AspNetCore/ExceptionlessExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class ExceptionlessExtensions {
1818
/// Registers the Exceptionless <see cref="IExceptionHandler"/> and required ASP.NET Core services
1919
/// for capturing unhandled exceptions. Call this in your service configuration alongside <c>app.UseExceptionHandler()</c>.
2020
/// </summary>
21-
public static IServiceCollection AddExceptionless(this IServiceCollection services) {
21+
public static IServiceCollection AddExceptionlessExceptionHandler(this IServiceCollection services) {
2222
services.AddHttpContextAccessor();
2323
if (!services.Any(descriptor =>
2424
descriptor.ServiceType == typeof(IExceptionHandler) &&

src/Platforms/Exceptionless.AspNetCore/readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ using Exceptionless;
3232

3333
var builder = WebApplication.CreateBuilder(args);
3434
builder.AddExceptionless(c => c.ApiKey = "API_KEY_HERE");
35-
builder.Services.AddExceptionless();
35+
builder.Services.AddExceptionlessExceptionHandler();
3636
builder.Services.AddProblemDetails();
3737

3838
In order to start gathering unhandled exceptions, you will need to register the Exceptionless middleware in your application
@@ -64,4 +64,4 @@ services.AddHttpContextAccessor()
6464
-------------------------------------
6565
Documentation and Support
6666
-------------------------------------
67-
Please visit http://exceptionless.io for documentation and support.
67+
Please visit http://exceptionless.io for documentation and support.

test/Exceptionless.Tests/Platforms/AspNetCoreExtensionsTests.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
namespace Exceptionless.Tests.Platforms {
1111
public class AspNetCoreExtensionsTests {
1212
[Fact]
13-
public void AddExceptionless_WhenCalled_RegistersAspNetCoreServices() {
13+
public void AddExceptionlessExceptionHandler_WhenCalled_RegistersAspNetCoreServices() {
1414
// Arrange
1515
var builder = WebApplication.CreateBuilder();
1616

1717
// Act
18-
builder.Services.AddExceptionless();
18+
builder.Services.AddExceptionlessExceptionHandler();
1919

2020
// Assert
2121
Assert.Contains(builder.Services, descriptor => descriptor.ServiceType == typeof(IHttpContextAccessor));
@@ -25,19 +25,34 @@ public void AddExceptionless_WhenCalled_RegistersAspNetCoreServices() {
2525
}
2626

2727
[Fact]
28-
public void AddExceptionless_WhenCalledTwice_DoesNotRegisterDuplicateExceptionHandlers() {
28+
public void AddExceptionlessExceptionHandler_WhenCalledTwice_DoesNotRegisterDuplicateExceptionHandlers() {
2929
// Arrange
3030
var builder = WebApplication.CreateBuilder();
3131

3232
// Act
33-
builder.Services.AddExceptionless();
34-
builder.Services.AddExceptionless();
33+
builder.Services.AddExceptionlessExceptionHandler();
34+
builder.Services.AddExceptionlessExceptionHandler();
3535

3636
// Assert
3737
Assert.Single(builder.Services, descriptor =>
3838
descriptor.ServiceType == typeof(IExceptionHandler) &&
3939
descriptor.ImplementationType == typeof(ExceptionlessExceptionHandler));
4040
}
41+
42+
[Fact]
43+
public void AddExceptionless_WhenCalledWithoutArguments_RegistersClientConfigurationServices() {
44+
// Arrange
45+
var builder = WebApplication.CreateBuilder();
46+
47+
// Act
48+
builder.Services.AddExceptionless();
49+
50+
// Assert
51+
Assert.Contains(builder.Services, descriptor => descriptor.ServiceType == typeof(ExceptionlessClient));
52+
Assert.DoesNotContain(builder.Services, descriptor =>
53+
descriptor.ServiceType == typeof(IExceptionHandler) &&
54+
descriptor.ImplementationType == typeof(ExceptionlessExceptionHandler));
55+
}
4156
}
4257
}
4358
#endif

0 commit comments

Comments
 (0)