/// <summary> /// 得到服务集合 /// </summary> /// <param name="assblemyArray">应用程序集(如果为null则获取当前应用的程序集)</param> /// <typeparam name="TService"></typeparam> /// <returns>得到继承serviceType的实现类</returns> public IEnumerable <TService> GetServices <TService>(Assembly[] assblemyArray = null) where TService : class { var types = (assblemyArray ?? AssemblyCommon.GetAssemblies()).SelectMany(x => x.GetTypes().Where(y => y.GetInterfaces().Contains(typeof(TService)))).ToList(); foreach (var type in types) { yield return(Activator.CreateInstance(type) as TService); } }
/// <summary> /// /// </summary> /// <param name="assblemyArray"></param> public ServiceProvider(Assembly[] assblemyArray = null) { _assblemyArray = assblemyArray ?? AssemblyCommon.GetAssemblies(); }