/// <summary> /// Returns services which are in the specified assembly. /// </summary> /// <param name="a">Assembly.</param> /// <returns>Services.</returns> public static StiServiceContainer GetServicesFromAssembly(Assembly a) { var serviceContainer = new StiServiceContainer(); if (a != null) { var types = GetTypesFromAssembly(a); Type typeService = typeof(StiService); foreach (Type type in types) { if (StiTypeFinder.FindType(type, typeService) && (!type.IsAbstract)) { try { var service = StiActivator.CreateObject(type) as StiService; if (service != null && service.ServiceType != null) { serviceContainer.Add(service); } } catch { } } } } return(serviceContainer); }
/// <summary> /// Returns all services of the type from the container. /// </summary> /// <param name="serviceType">Type of the returnable services.</param> /// <param name="getEnabled">If true then returns only enabled services.</param> /// <returns>Collection of services.</returns> public StiServiceContainer GetServices(Type serviceType, bool getEnabled, bool callBeforeGetService) { if (callBeforeGetService && BeforeGetService != null) { var args = new StiServiceActionEventArgs(StiServiceActionType.Get); BeforeGetService(serviceType, args); if (args.Processed) { var serviceContainer = new StiServiceContainer(); if (args.Services != null) { foreach (var service in args.Services) { serviceContainer.Add(service); } } return(serviceContainer); } } if (!noTypes) { StiServiceContainer services = typesHashtable[serviceType] as StiServiceContainer; if (services != null) { StiServiceContainer serv = new StiServiceContainer(); lock (services) { foreach (StiService service in services) { if (service.ServiceEnabled || (!getEnabled)) { serv.Add(service); } } } return(serv); } else { return(new StiServiceContainer()); } } else { StiServiceContainer services = new StiServiceContainer(true); foreach (StiService service in List) { if (service.ServiceType == serviceType && (service.ServiceEnabled || (!getEnabled))) { services.Add(service); } } return(services); } }