private void RegisterModules() { /* 注册IModule规则: * 1.获取所有继承IModule的接口 * 2.每个业务模块单独注册其下类型对应的所有实现 * 3.开启属性注入 */ var modelInterfaces = Depends.Where(p => typeof(IModule).IsAssignableFrom(p) && p.IsInterface && p != typeof(IModule)) .ToArray(); foreach (var modelInterface in modelInterfaces) { //找到接口的实现类 var sub = Depends.Where(p => modelInterface.IsAssignableFrom(p) && !p.IsInterface && !p.IsAbstract).ToList(); sub.ForEach(t => _builder.RegisterType(t).Named(t.Name, modelInterface).InstancePerLifetimeScope().OnActivated(e => RegisterProperties(e.Instance, e.Context))); } }
/// <summary> /// 根据类型获取所有实例 /// </summary> /// <param name="t"></param> /// <returns></returns> private List <Type> GetTypes(Type t) { return(Depends.Where(p => !p.IsAbstract && !p.IsInterface && t.IsAssignableFrom(p)).ToList()); }