private void UpdateCollection() { var feature = new CommandFeature(); _assemblyPartManager.PopulateFeature(feature); var results = new List <CommandDescriptor>(); var commandTypes = feature.Commands; foreach (var typeInfo in commandTypes) { var attribute = typeInfo.GetCustomAttribute <CommandAttribute>(); if (attribute != null && !attribute.Invalid) { results.Add(new CommandDescriptor() { Key = attribute.Id, Name = typeInfo.Name, CommandTypeInfo = typeInfo }); } } _collection = new CommandDescriptorCollection(new ReadOnlyCollection <CommandDescriptor>(results)); }
internal static IServiceCollection AddCommands(this IServiceCollection services, List <string> commandAssemblyArry) { var assemblyPartManager = new AssemblyPartManager(); services.AddSingleton(assemblyPartManager); if (!assemblyPartManager.FeatureProviders.OfType <CommandFeatureProvider>().Any()) { assemblyPartManager.FeatureProviders.Add(new CommandFeatureProvider()); } services.AddSingleton <ITypeActivatorCache, TypeActivatorCache>(); services.TryAddSingleton <ICommandDescriptorCollectionProvider, CommandDescriptorCollectionProvider>(); services.TryAddSingleton <ICommandDescriptorContainer, CommandDescriptorContainer>(); services.TryAddTransient <ICommandActivator, DefaultCommandActivator>(); var commandAssemblies = new List <Assembly>(); if (commandAssemblyArry != null && commandAssemblyArry.Any()) { var definedAssemblies = AssemblyUtil.GetAssembliesFromStrings(commandAssemblyArry.ToArray()); if (definedAssemblies.Any()) { commandAssemblies.AddRange(definedAssemblies); } } if (!commandAssemblies.Any()) { commandAssemblies.Add(Assembly.GetEntryAssembly()); } foreach (var assembly in commandAssemblies) { assemblyPartManager.AssemblyParts.Add(new AssemblyPart(assembly)); } var feature = new CommandFeature(); assemblyPartManager.PopulateFeature(feature); foreach (var command in feature.Commands.Select(c => c.AsType())) { services.TryAddTransient(command, command); } return(services); }