Created
April 18, 2025 15:50
-
-
Save khalidabuhakmeh/066fa8b2ced6f85424c16146ecb7b55b to your computer and use it in GitHub Desktop.
A Minimal API Endpoint that let's you look through registered dependencies
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
namespace WhatDoIHave; | |
public static class ServicesDebugger | |
{ | |
public static void UseServicesDebugger(this WebApplication app, IHostApplicationBuilder builder, | |
string path = "/__services") | |
{ | |
app.MapGet(path, () => | |
{ | |
// lang=html | |
var html = | |
$$""" | |
<html lang="en"> | |
<head> | |
<link | |
rel="stylesheet" | |
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" | |
> | |
<style> | |
td.break { | |
word-break: break-all; | |
white-space: normal; | |
font-style: italic; | |
} | |
th { | |
min-width: 100px; | |
} | |
.hidden { | |
display: none; | |
} | |
</style> | |
<script> | |
function filterTable(target) { | |
const filter = target.value.toLowerCase(); | |
document.querySelectorAll('tbody tr').forEach(row => { | |
const text = row.textContent.toLowerCase(); | |
row.classList.toggle('hidden', !text.includes(filter)); | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<main class="container-fluid"> | |
<h1>{{builder.Environment.ApplicationName}}</h1> | |
<form> | |
<input type="text" placeholder="Filter Services..." aria-label="Filter" onkeyup="filterTable(this)"> | |
</form> | |
<table class="striped"> | |
<thead> | |
<tr> | |
<th scope="col">Lifetime</th> | |
<th scope="col">Keyed</th> | |
<th scope="col">Service Type</th> | |
<th scope="col">Implementation Type</th> | |
</tr> | |
</thead> | |
<tbody> | |
{{string.Join("", | |
builder.Services | |
.OrderBy(x => x.Lifetime) | |
.Select(s => | |
// lang=html | |
$""" | |
<tr> | |
<td><strong>{s.Lifetime}</strong></td> | |
<td><strong>{(s.IsKeyedService ? $"Yes ( 🔑 {s.ServiceKey} )" : "No")}</strong></td> | |
<td class="break">{s.ServiceType.FullName}</td> | |
<td class="break">{s.ImplementationType?.FullName ?? "N/A"}</td> | |
</tr> | |
""") | |
)}} | |
</tbody> | |
</table> | |
</main> | |
</body> | |
</html> | |
"""; | |
return Results.Content(html, "text/html; charset=utf-8"); | |
}); | |
} | |
} |
Author
khalidabuhakmeh
commented
Apr 18, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment