LeonLu-MSFT san, thank you for your comments.
I understood I could not register same interface for two services.
I found other solution. My inpletations are as follows.
- separate two services as follows. public interface ISocketService : ICommunicationService
{
public ReactivePropertySlim<string> IPAddress { get; set; }
public ReactivePropertySlim<string> Port { get; set; }
} public interface ISerialPortService: ICommunicationService
{
public ReactivePropertySlim<string> PortName { get; set; }
public ReactivePropertySlim<string> BaudRate { get; set; }
} - change DI registration in CreateMauiApp() ....
builder.Services.AddSingleton<ISocketService, MySocketService>();
builder.Services.AddSingleton<ISerialPortService, MySerialPortService>();
.... - change communication class after userselection as follows. public class CommunicationViewModel
{
private ICommunication _service; public CommunicationViewModel(ISocketService socket, ISerialPortService serialport)
{
if (socket.IsConnected.Value) _service = socket;
if (serialport.IsConnected.Value) _service = serialport; ...
}
}
Thank you.