Esempio n. 1
0
        /// <summary>
        /// 初始化工厂
        /// </summary>
        static void InitFactory()
        {
            lock (PluginMenmberTable.SyncRoot)
            {
                PluginMenmberTable.Clear();
                var st = new Stopwatch();
                st.Start();

                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(q => q.GetCustomAttribute <PluginAssemblyAttribute>() != null))
                {
                    foreach (var plugType in assembly.GetExportedTypes().Where(q => q.IsClass &&
                                                                               !q.IsAbstract &&
                                                                               q.GetCustomAttribute <PluginClassAttribute>() != null))
                    {
                        var plugAttr = plugType.GetCustomAttribute <PluginClassAttribute>();

                        var member = new PluginClassMember()
                        {
                            FromType     = plugAttr.FromType,
                            TargetType   = plugType,
                            PluginMethod = new Dictionary <string, MethodInfo>()
                        };

                        foreach (var method in plugType.GetMethods().Where(q => q.IsPublic).Select(q => new
                        {
                            Method = q,
                            PluginAttr = q.GetCustomAttribute <PluginMethodAttribute>()
                        }).Where(q => q.PluginAttr != null))
                        {
                            //收集扩展方法
                            member.PluginMethod[method.PluginAttr.MethodName] = method.Method;
                        }

                        PluginMenmberTable.Add(member.FromType, member);
                    }
                }

                st.Stop();

                IsCustomize = PluginMenmberTable.Count > 0;
                LogEventProxy.FireLogRecord($"加载AOP配置耗时:{st.Elapsed.Milliseconds}");
            }
        }
Esempio n. 2
0
 public ClassMemberInvoker(PluginClassMember member)
 {
     _classMember    = member;
     _pluginInstance = _classMember == null ? null : Activator.CreateInstance(_classMember.TargetType);
 }