3

So it is a technical IDE question:

Let's say that I have blazor:

builder.Services.AddTransient<IHttpClient, HttpClient>();

and the httpClient looks like this:

public interface IHttpSowClient
{
    Task<List<Client>> SearchForClients(string searchKey);
}

public class HttpClient : IHttpClient
{
    private readonly IBaseHttpService _http;

    public HttpSowClient(IBaseHttpService http)
    {
        _http = http;
    }

    public async Task<List<KlientSOW>> SearchForClients(string searchKey)
    {
        //some logic
    }
}

And now in some component, I have of course @inject IHttpClient _http;

And the question is – is there any way to configure Visual Studio or maybe some other IDE?

To allow me in this component when I have like:

protected override async Task OnInitializedAsync()
{ 
    var x = _http.SearchForClients("test");
}

To when I press f12 on this SearchForClients for it to redirect me to the correct implemented method in HttpClient and not to interface IHttpSowClient method description** ??

And a similar question:

When I do var x = _http.SearchForClientsHavingSomething("test");

Is there any way for it to be known that should also allow me via IntelliSense to GENERATE method SearchForClientsHavingSomething in BOTH – interface and implementation** that is configured via startup or even in EVERY implementation that uses this interface???

It would be really helping me out / I like these features a lot and when doing it via interfaces for testing purposes I lost these features that I really like and use.

Please advise how You handle this. Do You always do this manually?


image for phuzi user enter image description here

Florian
  • 1,019
  • 6
  • 22
d00lar
  • 802
  • 7
  • 25
  • 1
    Visual Studio cannot determine which implementation of an interface has been injected unless you're debugging the code. If you're debugging the code then all methods will need to have been implemented, meaning that there's no reason to be able to need to add missing method! – phuzi Apr 14 '23 at 07:54
  • If you go to the method definition in the interface and press `ctrl + .` you should see a prompt to implement the method in all implementations of the interface. This will stub out the method with `throw new NotImplementedException();` – phuzi Apr 14 '23 at 07:57
  • no it is not - please check screenshot i added to post – d00lar Apr 14 '23 at 08:02
  • is there any way for it to automatlicly add this method to interdace ? and then simply implement interface will generate this method with notimplemented? – d00lar Apr 14 '23 at 08:03
  • @d00lar What you are trying to do defeats the purpose of DI. An interface decouples the definition from the implementation and now you want to bind both together again. If you don't want to use this clear separation and its advantages then just inject the class. – ViRuSTriNiTy Apr 14 '23 at 09:05
  • @ViRuSTriNiTy yes and no. i want to have this adventages COMBINED with adventages of not having interfaces. imho ide does thousent of harder things. so if in startup i defined witch implementation i want to use then IMHO it should be able also to redirrect to implemented method od be able to add method to interface and its implementation clasess don You think so ? – d00lar Apr 14 '23 at 09:29
  • @d00lar Just forget my previous comment as I was referring to multiple different implementations, you don't have this here. The only thing I can say is pressing `F12` means `Go to definition`, which opens the interface. The default shortcut for navigating to the implementation is `CTRL + F12`, so this is what you are searching for. This functionality sometimes works, sometimes not. – ViRuSTriNiTy Apr 14 '23 at 18:53
  • strange but this works :D / i didnt known that- please post as answer and i will accept - thanks ;) guess no way for implemented missing method like that or some other way ? ;P – d00lar Apr 15 '23 at 06:50

0 Answers0