From 3d863e72a66dd667f3218213786493226bf92d6d Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Tue, 19 Dec 2023 10:59:47 +0100 Subject: [PATCH] refactor: prefer clientFactories parameter to addClientFactory --- README.md | 4 +++- example/coap_discovery.dart | 2 +- example/coap_dns_sd_discovery.dart | 6 +++++- example/coaps_readproperty.dart | 7 ++++++- example/complex_example.dart | 18 +++++++++++------- example/core_link_format_discovery.dart | 2 +- example/example.dart | 11 ++++++++--- example/http_basic_authentication.dart | 6 +++++- test/binding_http/http_test.dart | 7 ++++--- test/core/consumed_thing_test.dart | 2 +- 10 files changed, 45 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 3270bde0..2537f107 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,9 @@ import 'package:dart_wot/dart_wot.dart'; Future main(List args) async { final CoapClientFactory coapClientFactory = CoapClientFactory(); - final servient = Servient()..addClientFactory(coapClientFactory); + final servient = Servient( + protocolClients: [coapClientFactory] + ); final wot = await servient.start(); final thingDescriptionJson = ''' diff --git a/example/coap_discovery.dart b/example/coap_discovery.dart index 494cebe8..10e63882 100644 --- a/example/coap_discovery.dart +++ b/example/coap_discovery.dart @@ -30,7 +30,7 @@ Future handleThingDescription( } Future main(List args) async { - final servient = Servient()..addClientFactory(CoapClientFactory()); + final servient = Servient(clientFactories: [CoapClientFactory()]); final wot = await servient.start(); final uri = Uri.parse('coap://plugfest.thingweb.io:5683/testthing'); diff --git a/example/coap_dns_sd_discovery.dart b/example/coap_dns_sd_discovery.dart index 48013414..6dbb1357 100644 --- a/example/coap_dns_sd_discovery.dart +++ b/example/coap_dns_sd_discovery.dart @@ -12,7 +12,11 @@ void handleThingDescription(ThingDescription thingDescription) => print('Discovered TD with title "${thingDescription.title}".'); Future main(List args) async { - final servient = Servient()..addClientFactory(CoapClientFactory()); + final servient = Servient( + clientFactories: [ + CoapClientFactory(), + ], + ); final wot = await servient.start(); final uri = Uri.parse('_wot._udp.local'); diff --git a/example/coaps_readproperty.dart b/example/coaps_readproperty.dart index 0d323ce9..469a11f0 100644 --- a/example/coaps_readproperty.dart +++ b/example/coaps_readproperty.dart @@ -35,7 +35,12 @@ Future main(List args) async { ), pskCredentialsCallback: _pskCredentialsCallback, ); - final servient = Servient()..addClientFactory(coapClientFactory); + + final servient = Servient( + clientFactories: [ + coapClientFactory, + ], + ); final wot = await servient.start(); diff --git a/example/complex_example.dart b/example/complex_example.dart index 5868110a..b9b1e766 100644 --- a/example/complex_example.dart +++ b/example/complex_example.dart @@ -112,15 +112,19 @@ Future basicCredentialsCallback( } Future main() async { - const coapConfig = CoapConfig(blocksize: 64); - final CoapClientFactory coapClientFactory = CoapClientFactory( - coapConfig: coapConfig, + final coapClientFactory = CoapClientFactory( + coapConfig: const CoapConfig(blocksize: 64), ); - final HttpClientFactory httpClientFactory = + + final httpClientFactory = HttpClientFactory(basicCredentialsCallback: basicCredentialsCallback); - final servient = Servient() - ..addClientFactory(coapClientFactory) - ..addClientFactory(httpClientFactory); + + final servient = Servient( + clientFactories: [ + coapClientFactory, + httpClientFactory, + ], + ); final wot = await servient.start(); final thingDescription = ThingDescription(thingDescriptionJson); diff --git a/example/core_link_format_discovery.dart b/example/core_link_format_discovery.dart index 1cfcfbca..aad9a4b8 100644 --- a/example/core_link_format_discovery.dart +++ b/example/core_link_format_discovery.dart @@ -12,7 +12,7 @@ const propertyName = 'status'; const actionName = 'toggle'; Future main(List args) async { - final servient = Servient()..addClientFactory(CoapClientFactory()); + final servient = Servient(clientFactories: [CoapClientFactory()]); final wot = await servient.start(); diff --git a/example/example.dart b/example/example.dart index f81843b5..95859529 100644 --- a/example/example.dart +++ b/example/example.dart @@ -28,9 +28,14 @@ Future main(List args) async { HttpClientFactory(basicCredentialsCallback: basicCredentialsCallback); final MqttClientFactory mqttClientFactory = MqttClientFactory(); final servient = Servient() - ..addClientFactory(coapClientFactory) - ..addClientFactory(httpClientFactory) - ..addClientFactory(mqttClientFactory); + final servient = Servient( + clientFactories: [ + coapClientFactory, + httpClientFactory, + mqttClientFactory, + ], + ); + final wot = await servient.start(); const thingDescriptionJson = ''' diff --git a/example/http_basic_authentication.dart b/example/http_basic_authentication.dart index 2b787b00..b8dd62ac 100644 --- a/example/http_basic_authentication.dart +++ b/example/http_basic_authentication.dart @@ -70,7 +70,11 @@ Future basicCredentialsCallback( Future main(List args) async { final HttpClientFactory httpClientFactory = HttpClientFactory(basicCredentialsCallback: basicCredentialsCallback); - final servient = Servient()..addClientFactory(httpClientFactory); + final servient = Servient( + clientFactories: [ + httpClientFactory, + ], + ); final wot = await servient.start(); final thingDescription = ThingDescription(thingDescriptionJson); diff --git a/test/binding_http/http_test.dart b/test/binding_http/http_test.dart index 175ae8e9..fd173bef 100644 --- a/test/binding_http/http_test.dart +++ b/test/binding_http/http_test.dart @@ -128,13 +128,14 @@ void main() { ]) async => bearerCredentialsStore[uri.host]; - final servient = Servient() - ..addClientFactory( + final servient = Servient( + clientFactories: [ HttpClientFactory( basicCredentialsCallback: basicCredentialsCallback, bearerCredentialsCallback: bearerCredentialsCallback, ), - ); + ], + ); final wot = await servient.start(); final consumedThing = await wot.consume(parsedTd); diff --git a/test/core/consumed_thing_test.dart b/test/core/consumed_thing_test.dart index 5e1bf26a..66b38962 100644 --- a/test/core/consumed_thing_test.dart +++ b/test/core/consumed_thing_test.dart @@ -284,7 +284,7 @@ void main() { final parsedTd = ThingDescription(thingDescriptionJson); - final servient = Servient()..addClientFactory(HttpClientFactory()); + final servient = Servient(clientFactories: [HttpClientFactory()]); final wot = await servient.start(); final uriVariables = {'value': 'SFRUUEJJTiBpcyBhd2Vzb21l'};