nenoNaninu / TypedSignalR.Client.TypeScript

TypeScript source generator to provide strongly typed SignalR clients by analyzing C# type definitions.
MIT License
90 stars 9 forks source link

How to ignore dependency injection arguments? #201

Open gcoda opened 3 months ago

gcoda commented 3 months ago

Is there an easy way to make this work? Overloading breaks runtime DI, using IDbContextFactory<DataContext> ctx inside of HubInterface breaks Tapper.

[Hub]
public interface IInventoryHub
{
    Task<Shelf[]> GetShelves();
}

public class InventoryHub : Hub<IInventoryReceiver>
{
    public async Task<Shelf[]> GetShelves(IDbContextFactory<DataContext> ctx)
    {
        await using var db = await ctx.CreateDbContextAsync();
        var shelves = db.Shelves.ToArray();
        return shelves;
    }
}

Edit: it is possible to use DI in constructor

public class InventoryHub(IDbContextFactory<DataContext> ctx) : Hub<IInventoryReceiver>, IInventoryHub

and it works, so not big deal

nenoNaninu commented 3 months ago

Currently, dependency injection using method parameters is not supported.