Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to ignore dependency injection arguments? #201

Open
gcoda opened this issue May 17, 2024 · 1 comment
Open

How to ignore dependency injection arguments? #201

gcoda opened this issue May 17, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@gcoda
Copy link

gcoda commented May 17, 2024

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
Copy link
Owner

Currently, dependency injection using method parameters is not supported.

@nenoNaninu nenoNaninu added the enhancement New feature or request label May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants