Specific settings with MEF

We have an interface that will be implemented by classes that, for example, are involved in transporting data over a network or COM ports.

Call it IDataTransporter, and we have 2 implementations:

ComPortDataTransporter and TcpDataTransporter.

Obviously, these two require a very different configuration.

The first one has settings like buadrate, start / stop bits, etc ... the second one has settings like ip address and port.

Are there any recommendations on this? In the end, we want the user to be able to download the "part" and configure it once.

Thnx.

+3
source share
1 answer

, - .

, - :

public interface IDataTransporterSettings 
{
    // any common settings are defined here
}

... , IDataTrasporter :

public interface IDataTransporter
{
    IDataTransporterSettings Settings { get; }
}

... "" , :

public class TcpDataTransporterSettings : IDataTransporterSettings
{
    public string Address { get; set; }
    public int Port { get; set; }
}

TcpDataTransporter Settings, //.

- (TextBox , NumericUpDown int ..).

, , .

, , , , , .

+4

Source: https://habr.com/ru/post/1709004/


All Articles