-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored raygunclient to be used as a singleton and cleaned up the …
…dependencies for middleware to remove middleware settings
- Loading branch information
1 parent
267a668
commit 54e3b89
Showing
25 changed files
with
652 additions
and
597 deletions.
There are no files selected for viewing
30 changes: 0 additions & 30 deletions
30
Mindscape.Raygun4Net.AspNetCore.Tests/ExampleRaygunAspNetCoreClientProvider.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
Mindscape.Raygun4Net.AspNetCore/ApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
namespace Mindscape.Raygun4Net.AspNetCore; | ||
|
||
public static class ApplicationBuilderExtensions | ||
{ | ||
public static IApplicationBuilder UseRaygun(this IApplicationBuilder app) | ||
{ | ||
return app.UseMiddleware<RaygunMiddleware>(); | ||
} | ||
|
||
public static IServiceCollection AddRaygun(this IServiceCollection services, IConfiguration? configuration = null, Action<RaygunSettings>? configure = null) | ||
{ | ||
// Fetch settings from configuration or use default settings | ||
var settings = configuration?.GetSection("RaygunSettings").Get<RaygunSettings>() ?? new RaygunSettings(); | ||
|
||
// Override settings with user-provided settings | ||
configure?.Invoke(settings); | ||
|
||
services.TryAddSingleton(settings); | ||
services.TryAddSingleton(s => new RaygunClient(s.GetService<RaygunSettings>())); | ||
services.AddHttpContextAccessor(); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
Mindscape.Raygun4Net.AspNetCore/Builders/RaygunAspNetCoreResponseMessageBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Net; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Mindscape.Raygun4Net.AspNetCore; | ||
|
||
internal static class HttpRequestExtensions | ||
{ | ||
/// <summary> | ||
/// Returns true if the IP address of the request originator was 127.0.0.1 or if the IP address of the request was the same as the server's IP address. | ||
/// </summary> | ||
/// <remarks> | ||
/// Credit to Filip W for the initial implementation of this method. | ||
/// See http://www.strathweb.com/2016/04/request-islocal-in-asp-net-core/ | ||
/// </remarks> | ||
public static bool IsLocal(this HttpRequest req) | ||
{ | ||
var connection = req.HttpContext.Connection; | ||
if (connection.RemoteIpAddress != null) | ||
{ | ||
return (connection.LocalIpAddress != null && connection.RemoteIpAddress.Equals(connection.LocalIpAddress)) || IPAddress.IsLoopback(connection.RemoteIpAddress); | ||
} | ||
|
||
// for in memory TestServer or when dealing with default connection info | ||
if (connection.RemoteIpAddress == null && connection.LocalIpAddress == null) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
153 changes: 0 additions & 153 deletions
153
Mindscape.Raygun4Net.AspNetCore/RaygunAspNetMiddleware.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.