/// <summary> /// Gets all trackers /// </summary> /// <returns>All available shipment trackers</returns> protected virtual IList <IShipmentTracker> GetAllTrackers() { return(_typeSearcher.ClassesOfType <IShipmentTracker>() //exclude this one .Where(x => x != typeof(GeneralShipmentTracker)) .Select(x => x as IShipmentTracker) .ToList()); }
/// <summary> /// Register type Converters /// </summary> /// <param name="typeSearcher"></param> private static void RegisterTypeConverter(ITypeSearcher typeSearcher) { //find converters provided by other assemblies var converters = typeSearcher.ClassesOfType <ITypeConverter>(); //create and sort instances of typeConverter var instances = converters .Select(converter => (ITypeConverter)Activator.CreateInstance(converter)) .OrderBy(converter => converter.Order); foreach (var item in instances) { item.Register(); } }
/// <summary> /// Run startup tasks /// </summary> /// <param name="typeSearcher">Type finder</param> private static void ExecuteStartupTasks(ITypeSearcher typeSearcher) { //find startup tasks provided by other assemblies var startupTasks = typeSearcher.ClassesOfType <IStartupTask>(); //create and sort instances of startup tasks var instances = startupTasks .Select(startupTask => (IStartupTask)Activator.CreateInstance(startupTask)) .OrderBy(startupTask => startupTask.Order); //execute tasks foreach (var task in instances) { task.Execute(); } }
/// <summary> /// Register and init AutoMapper /// </summary> /// <param name="typeSearcher">Type finder</param> private static void InitAutoMapper(ITypeSearcher typeSearcher) { //find mapper configurations provided by other assemblies var mapperConfigurations = typeSearcher.ClassesOfType <IAutoMapperProfile>(); //create and sort instances of mapper configurations var instances = mapperConfigurations .Where(mapperConfiguration => PluginExtensions.OnlyInstalledPlugins(mapperConfiguration)) .Select(mapperConfiguration => (IAutoMapperProfile)Activator.CreateInstance(mapperConfiguration)) .OrderBy(mapperConfiguration => mapperConfiguration.Order); //create AutoMapper configuration var config = new MapperConfiguration(cfg => { foreach (var instance in instances) { cfg.AddProfile(instance.GetType()); } }); //register automapper AutoMapperConfig.Init(config); }