Skip to content

Add extensions for DI #27

@VictorioBerra

Description

@VictorioBerra

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");
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions