# initMessageSource method

1. @protected

Future<void> initMessageSource()

Initializes the `MessageSource` for this context.

This is invoked during refresh to set up i18n message resolution. By default, it discovers non-abstract subclasses of `MessageSource`, wraps them in a `DelegatingMessageSource`, and registers the result in the pod factory.

Subclasses can override this method to provide a custom message source strategy.

This is part of Jetleaf – a framework which developers can use to build web applications.

## Implementation

    @protected
    Future<void> initMessageSource() async {
      if (podFactory != null && await containsLocalPod(MESSAGE_SOURCE_POD_NAME)) {
        _messageSource = await getPod(MESSAGE_SOURCE_POD_NAME);
      } else {
        final mcl = Class<MessageSource>(null, PackageNames.CORE);
        final del = Class<DelegatingMessageSource>(null, PackageNames.CORE);
        final sources = <MessageSource>[];
        final classes = mcl.getSubClasses().where((cl) => cl.isInvokable());

        for(final cl in classes) {
          final defc = cl.getNoArgConstructor();
          if(defc != null) {
            final source = defc.newInstance();
            sources.add(source);
          } else {
            if(logger.getIsWarnEnabled()) {
              logger.warn("Message ${cl.getName()} does not have a no-arg constructor");
            }
          }
        }

        _messageSource = DelegatingMessageSource(sources);

        await registerSingleton(
          MESSAGE_SOURCE_POD_NAME,
          del,
          object: ObjectHolder<MessageSource>(
            _messageSource!,
            packageName: PackageNames.CORE,
            qualifiedName: del.getQualifiedName()
          )
        );
      }

      return Future.value();
    }