Exemplo n.º 1
0
 void svc_ModuleLoaded(object sender, GenericEventArgs <IModuleInfo> e)
 {
     ModuleLoaded.Fire(this, e);
 }
        internal ModuleInfo LoadAssembly(Assembly assembly)
        {
            var assemblyName = assembly.GetName();

            Debug.WriteLine(string.Format("IoC: Loading assembly '{0}'", assemblyName), Constants.TraceCategoryName);

            Type imodule = FindIModuleType(assembly);

            if (imodule == null)
            {
                return(null);
            }

            object instance = ObjectFactory.CreateObject(imodule, RootWorkItem.Instance);

            var info = new ModuleInfo
            {
                Assembly     = assembly,
                AssemblyFile = assemblyName.CodeBase,
                Instance     = instance
            };

            lock (m_syncRoot)
            {
                m_loadedModules.Add(info);
            }

#if NETSTANDARD1_3
            var loadMethod = imodule.GetRuntimeMethod("Load", null);
#else
            var loadMethod = imodule.GetMethod("Load", BindingFlags.Public | BindingFlags.Instance);
#endif
            if (loadMethod != null)
            {
                try
                {
                    loadMethod.Invoke(instance, null);
                }
                catch (Exception ex)
                {
                    throw ex.InnerException;
                }
            }

            var addServices = imodule.GetMethod("AddServices", BindingFlags.Public | BindingFlags.Instance);
            if (addServices != null)
            {
                try
                {
                    addServices.Invoke(instance, null);
                }
                catch (Exception ex)
                {
                    throw ex.InnerException;
                }
            }

            ModuleLoaded.Fire(this, new GenericEventArgs <IModuleInfo>(info));

            return(info);
        }