예제 #1
0
        public async Task <ModuleInfo> AddModuleAsync(Type type)
        {
            await _moduleLock.WaitAsync().ConfigureAwait(false);

            try
            {
                var typeInfo = type.GetTypeInfo();

                if (_typedModuleDefs.ContainsKey(type))
                {
                    throw new ArgumentException($"This module has already been added.");
                }

                var module = ModuleClassBuilder.Build(this, typeInfo).FirstOrDefault();

                if (module.Value == default(ModuleInfo))
                {
                    throw new InvalidOperationException($"Could not build the module {type.FullName}, did you pass an invalid type?");
                }

                _typedModuleDefs[module.Key] = module.Value;

                return(LoadModuleInternal(module.Value));
            }
            finally
            {
                _moduleLock.Release();
            }
        }
예제 #2
0
        public async Task <IEnumerable <ModuleInfo> > AddModulesAsync(Assembly assembly)
        {
            await _moduleLock.WaitAsync().ConfigureAwait(false);

            try
            {
                var types      = ModuleClassBuilder.Search(assembly).ToArray();
                var moduleDefs = ModuleClassBuilder.Build(types, this);

                foreach (var info in moduleDefs)
                {
                    _typedModuleDefs[info.Key] = info.Value;
                    LoadModuleInternal(info.Value);
                }

                return(moduleDefs.Select(x => x.Value).ToImmutableArray());
            }
            finally
            {
                _moduleLock.Release();
            }
        }