DataTables / Editor-NET

.NET Framework and .NET Core server-side libraries for Editor
Other
15 stars 12 forks source link

Add extensions for DI #27

Open VictorioBerra opened 3 months ago

VictorioBerra commented 3 months ago

Usage:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllersWithViews();
builder.Services.AddDataTables("sqlite", "Data Source=./db.sqlite"); // <----------- NEW!

var app = builder.Build();

app.UseStaticFiles();

app.MapDefaultControllerRoute();

app.Run();

Usage:

public CarsController(Database db) : ControllerBase // new primary constructors
{
  [HttpGet("DataTable")]
  [HttpPost("DataTable")]
  public ActionResult<DtResponse> GetDataTable()
  {
    // db.XYZ
  }
}

I have created my own but I am having other issues with my approach in the context of integration tests with TestHost and a custom WebApplicationFactory.

DbProviderFactories.RegisterFactory("Microsoft.Data.Sqlite", SqlClientFactory.Instance);
services.AddScoped((sp) =>
{
    return new Database("sqlite", sqliteConnectionString, "Microsoft.Data.Sqlite");
});
AllanJard commented 3 months ago

Interesting idea - thanks for suggesting it. It isn't one that was on my radar, but I will consider it in future.