MelbourneDeveloper / Device.Net

A C# cross platform connected device framework
MIT License
629 stars 121 forks source link

Added factory builder. #194

Open fiseni opened 3 years ago

fiseni commented 3 years ago

Hi,

These changes offer an alternative way of building factories. It tends to simplify the usage during the initialization/definition phase. Perhaps it's more intuitive? (that's a bit subjective). I tried not to introduce any breaking changes, so any existing code should work, the existing API remains as it is.

For now, it covers only WindowsHidDeviceFactory, and it's provided just as a sample. If this approach is preferred, then it can be extended to include the rest of the components. So, this PR is incomplete

Sample usage:

// Optional
var loggerFactory = LoggerFactory.Create((builder) =>
{
    _ = builder.AddDebug().SetMinimumLevel(LogLevel.Trace);
});

var factories = new FactoryBuilder(loggerFactory)
    .CreateWindowsHidDeviceFactory(new FilterDeviceDefinition())
    .CreateWindowsHidDeviceFactory(new FilterDeviceDefinition[]
    {
        new FilterDeviceDefinition(),
        new FilterDeviceDefinition(),
    })
    .Build();