build method

Implementation

MineralClientContract build() {
  ioc
    ..bind(LoggerContract, () => _logger)
    ..bind(EnvContract, () => _env);

  _validateEnvironment();
  _createCache();

  final token = _env.get<String>(AppEnv.token);
  final httpVersion = int.parse(_env.get(AppEnv.httpVersion));
  final shardVersion = int.parse(_env.get(AppEnv.wssVersion));
  final intent = int.parse(_env.get(AppEnv.intent));

  final http = HttpClient(
      config: HttpClientConfigImpl(
          baseUrl: 'https://discord.com/api/v$httpVersion',
          headers: {
        Header.userAgent('Mineral'),
        Header.contentType('application/json'),
      }));

  final shardConfig =
      ShardingConfig(token: token, intent: intent, version: shardVersion);

  final marshaller = Marshaller(_logger, _cache!);
  final datastore = DataStore(http);
  final commandInteractionManager = CommandInteractionManager(marshaller);

  ioc
    ..bind(MarshallerContract, () => marshaller)
    ..bind(DataStoreContract, () => datastore)
    ..bind(
        CommandInteractionManagerContract, () => commandInteractionManager);

  final packetListener = PacketListener();
  final eventListener = EventListener();
  final providerManager = ProviderManager();

  final kernel = Kernel(
    _hasDefinedDevPort,
    _devPort,
    watcherConfig: _watcherConfig,
    logger: _logger,
    environment: _env,
    httpClient: http,
    config: shardConfig,
    packetListener: packetListener,
    providerManager: providerManager,
    eventListener: eventListener,
    marshaller: marshaller,
    dataStore: datastore,
    commands: commandInteractionManager,
  );

  datastore.kernel = kernel;
  packetListener.kernel = kernel;

  datastore.init();
  packetListener.init();

  final client = MineralClient(kernel);

  for (final provider in _providers) {
    providerManager.register(provider(client));
  }

  return client;
}