### MongoDB C# Driver: Using Standard GUIDs Source: https://github.com/mehdihadeli/awesome-software-architecture/blob/main/docs/database/nosql/mongodb.md Demonstrates the configuration for using standard GUID representations in the MongoDB C# driver. This ensures consistent handling of GUIDs across different systems. ```csharp BsonSerializer.RegisterSerializer(new GuidSerializer(BsonGuidRepresentation.Standard)); ``` -------------------------------- ### MongoDB Shell/Compass: Query with GUID Source: https://github.com/mehdihadeli/awesome-software-architecture/blob/main/docs/database/nosql/mongodb.md Demonstrates how to query MongoDB using a GUID in the shell or Compass. This is useful when your application uses GUIDs as identifiers and you need to find specific records. ```javascript db.collection.find({ _id: "a1b2c3d4-e5f6-7890-1234-567890abcdef" }); ``` -------------------------------- ### OpenTelemetry Extensions for ASP.NET Core Source: https://github.com/mehdihadeli/awesome-software-architecture/blob/main/docs/microservices/observability/distributed-tracing.md Example of extending OpenTelemetry services in an ASP.NET Core application. This snippet shows how to configure OpenTelemetry, which is essential for distributed tracing. ```csharp using OpenTelemetry.Extensions.Hosting; using OpenTelemetry.Trace; namespace TodoApi { public static class OpenTelemetryExtensions { public static IServiceCollection AddOpenTelemetryTracing(this IServiceCollection services) { services.AddOpenTelemetry() .WithTracing(builder => { builder .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddOtlpExporter(); }); return services; } } } ``` -------------------------------- ### Basic Concurrency Handling in Entity Framework Core Source: https://github.com/mehdihadeli/awesome-software-architecture/blob/main/docs/concurrency.md Demonstrates basic optimistic concurrency handling in Entity Framework Core. Ensure your entity has a concurrency token property. ```csharp public class Blog { public int BlogId { get; set; } public string Url { get; set; } // Concurrency token [Timestamp] public byte[] RowVersion { get; set; } } ``` -------------------------------- ### HostingApplicationDiagnostics in ASP.NET Core Source: https://github.com/mehdihadeli/awesome-software-architecture/blob/main/docs/microservices/observability/diagnostics.md This snippet illustrates the HostingApplicationDiagnostics class in ASP.NET Core, which manages diagnostic events related to the application's lifecycle and request processing. ```csharp internal class HostingApplicationDiagnostics { private readonly DiagnosticListener _diagnosticListener; private readonly HostingEventSource _hostingEventSource; public HostingApplicationDiagnostics(DiagnosticListener diagnosticListener, HostingEventSource hostingEventSource) { _diagnosticListener = diagnosticListener ?? throw new ArgumentNullException(nameof(diagnosticListener)); _hostingEventSource = hostingEventSource ?? throw new ArgumentNullException(nameof(hostingEventSource)); } public void BeginRequest(HttpContext httpContext) { var requestId = httpContext.Connection.Id; var request = httpContext.Request; var requestPath = request.Path.ToString(); var requestMethod = request.Method; _hostingEventSource.RequestStarting(requestId, requestPath, requestMethod); _diagnosticListener.Write("Microsoft.AspNetCore.Hosting.BeginRequest", new { httpContext }); } public void EndRequest(HttpContext httpContext) { var requestId = httpContext.Connection.Id; var response = httpContext.Response; var responseStatusCode = response.StatusCode; var requestMethod = httpContext.Request.Method; _hostingEventSource.RequestFinished(requestId, responseStatusCode, requestMethod); _diagnosticListener.Write("Microsoft.AspNetCore.Hosting.EndRequest", new { httpContext }); } public void Shutdown() { _hostingEventSource.HostShutdown(); _diagnosticListener.Write("Microsoft.AspNetCore.Hosting.Shutdown", null); } public void ApplicationStopping() { _hostingEventSource.ApplicationStopping(); _diagnosticListener.Write("Microsoft.AspNetCore.Hosting.ApplicationStopping", null); } public void ApplicationStopped() { _hostingEventSource.ApplicationStopped(); _diagnosticListener.Write("Microsoft.AspNetCore.Hosting.ApplicationStopped", null); } } ```