I maintain a class library which contains several reference implementations to demonstrate how the library should be used. I have reference implementations for .Net Framework, core, .NET 5 and now I have added a reference implementation for .NET 6 using minimal APIs.
For all of my other reference implementations I have added the ExcludeFromCodeCoverage attribute using System.Diagnostics.CodeAnalysis to all of their containing classes. How would I do something similar for a .NET 6 minimal API?
My program.cs looks like this:
using Microsoft.AspNetCore.Mvc;
using SharedDataLayer.Repositories;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<PaymentRepository>();
var app = builder.Build();
app.MapGet("/Payments", ([FromServices] PaymentRepository repo) =>
{
return repo.GetPayments();
});
app.Run();
Your Program.cs shoud look like this:
using Microsoft.AspNetCore.Mvc;
using SharedDataLayer.Repositories;
using System.Diagnostics.CodeAnalysis;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<PaymentRepository>();
var app = builder.Build();
app.MapGet("/Payments", ([FromServices] PaymentRepository repo) =>
{
return repo.GetPayments();
});
app.Run();`
[ExcludeFromCodeCoverage]
public partial class Program { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With