jamesmontemagno / MauiApp-DI

70 stars 29 forks source link

Why when you register service for IConnectivy you pass as argument an specific implementation? #6

Open ComptonAlvaro opened 1 year ago

ComptonAlvaro commented 1 year ago

When you register the services for IConnectivity, you use this code:

builder.Services.AddSingleton<IConnectivity>((e) => Connectivity.Current);

If I don't understand wrong, it means that when IConnectivity is requested, it is passeed Connectivity.Current, that is a specific implementation of IConnectivity. So it is not possible to pass another implementation.

So my cuestion is, if I have an own implementation of IConnectivity, how could I decide to use the Connectivity.Current or my own implementation?

Perhaps with the connectivity it has not too much sense, but I am thinking in general and for example in unit tests, in which I could be interested in using my own imlpementantion.

Thanks.