diff --git a/src/client/LibplanetConsole.Clients/ApplicationBase.cs b/src/client/LibplanetConsole.Clients/ApplicationBase.cs index acafa5ee..4bd1827b 100644 --- a/src/client/LibplanetConsole.Clients/ApplicationBase.cs +++ b/src/client/LibplanetConsole.Clients/ApplicationBase.cs @@ -34,6 +34,7 @@ protected ApplicationBase(ApplicationOptions options) _container.ComposeExportedValue(_client); _container.ComposeExportedValue(_client); _container.ComposeExportedValue(_client); + _container.ComposeExportedValues(options.Components); _clientServiceContext = _container.GetValue(); _clientServiceContext.EndPoint = options.EndPoint; _container.GetValue(); diff --git a/src/common/LibplanetConsole.Frameworks/Extensions/CompositionContainerExtensions.cs b/src/common/LibplanetConsole.Frameworks/Extensions/CompositionContainerExtensions.cs index eee5ed24..71ac0e16 100644 --- a/src/common/LibplanetConsole.Frameworks/Extensions/CompositionContainerExtensions.cs +++ b/src/common/LibplanetConsole.Frameworks/Extensions/CompositionContainerExtensions.cs @@ -1,4 +1,6 @@ +using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; +using System.ComponentModel.Composition.Primitives; namespace LibplanetConsole.Frameworks.Extensions; @@ -7,4 +9,22 @@ public static class CompositionContainerExtensions public static T GetValue(this CompositionContainer @this) => @this.GetExportedValue() ?? throw new InvalidOperationException($"'{typeof(T)}' is not found."); + + public static void ComposeExportedValues(this CompositionContainer @this, object[] components) + { + var batch = new CompositionBatch(); + foreach (var item in components) + { + var contractName = AttributedModelServices.GetContractName(item.GetType()); + var typeIdentity = AttributedModelServices.GetTypeIdentity(item.GetType()); + var metadata = new Dictionary + { + { "ExportTypeIdentity", typeIdentity }, + }; + var export = new Export(contractName, metadata, () => item); + batch.AddExport(export); + } + + @this.Compose(batch); + } } diff --git a/src/console/LibplanetConsole.Consoles/ApplicationBase.cs b/src/console/LibplanetConsole.Consoles/ApplicationBase.cs index bb6752d7..07b89990 100644 --- a/src/console/LibplanetConsole.Consoles/ApplicationBase.cs +++ b/src/console/LibplanetConsole.Consoles/ApplicationBase.cs @@ -38,6 +38,7 @@ protected ApplicationBase(ApplicationOptions options) _container.ComposeExportedValue(_clients); _container.ComposeExportedValue(_clients); _container.ComposeExportedValue(_clients); + _container.ComposeExportedValues(options.Components); _consoleContext = _container.GetValue(); _consoleContext.EndPoint = options.EndPoint; _container.GetValue(); diff --git a/src/node/LibplanetConsole.Nodes/ApplicationBase.cs b/src/node/LibplanetConsole.Nodes/ApplicationBase.cs index 1abd3d61..80c851a8 100644 --- a/src/node/LibplanetConsole.Nodes/ApplicationBase.cs +++ b/src/node/LibplanetConsole.Nodes/ApplicationBase.cs @@ -1,5 +1,8 @@ using System.Collections; +using System.ComponentModel; using System.ComponentModel.Composition; +using System.ComponentModel.Composition.Hosting; +using System.ComponentModel.Composition.Primitives; using System.Diagnostics; using LibplanetConsole.Common; using LibplanetConsole.Frameworks; @@ -34,7 +37,8 @@ protected ApplicationBase(ApplicationOptions options) _container.ComposeExportedValue(_node); _container.ComposeExportedValue(_node); _container.ComposeExportedValue(_node); - Array.ForEach(options.Components, _container.ComposeExportedValue); + _container.ComposeExportedValues(options.Components); + _container.ComposeParts(options.Components); _nodeContext = _container.GetValue(); _nodeContext.EndPoint = options.EndPoint; _logger.Debug(options.EndPoint.ToString());