Line data Source code
1 : import 'package:ws_game_server/services/client_connections_service.dart';
2 :
3 : /// Services are nullable so that we can only provide a service if none exists,
4 : /// allowing for mocks to be set in tests.
5 : ///
6 : /// All get_Service functions return non-nullable types. Ensuring the
7 : /// services are not null when they are accessed is up to the developer.
8 : class Locator {
9 0 : static ClientConnectionsService getClientConnectionsService() =>
10 : _clientConnectionsService!;
11 :
12 : // Sets _clientConnectionsService if not already set
13 0 : static void provide({ClientConnectionsService? service}) {
14 : _clientConnectionsService ??= service;
15 : }
16 :
17 : // Sets _clientConnectionsService to the default, if not already set
18 0 : static ClientConnectionsService provideDefaultClientConnectionsService() {
19 0 : _clientConnectionsService ??= ClientConnectionsService();
20 : return _clientConnectionsService!;
21 : }
22 :
23 0 : static bool get hasClientConnectionsService =>
24 : _clientConnectionsService != null;
25 0 : static bool get needsClientConnectionsService =>
26 : _clientConnectionsService == null;
27 :
28 : static ClientConnectionsService? _clientConnectionsService;
29 : }
|