/// <summary> /// Adds all saga state machines in the specified assemblies matching the namespace. If you are using both state machine and regular sagas, be /// sure to call AddSagasFromNamespaceContaining after calling this one. /// </summary> /// <param name="configurator"></param> /// <param name="type">The type to use to identify the assembly and namespace to scan</param> /// <param name="filter"></param> public static void AddSagaStateMachinesFromNamespaceContaining(this IRegistrationConfigurator configurator, Type type, Func <Type, bool> filter = null) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (type.Assembly == null || type.Namespace == null) { throw new ArgumentException($"The type {TypeMetadataCache.GetShortName(type)} is not in an assembly with a valid namespace", nameof(type)); } IEnumerable <Type> types; if (filter != null) { bool IsAllowed(Type candidate) { return(TypeMetadataCache.IsSagaStateMachineOrDefinition(candidate) && !TypeMetadataCache.IsFutureOrDefinition(type) && filter(candidate)); } types = FindTypesInNamespace(type, IsAllowed); } else { types = FindTypesInNamespace(type, TypeMetadataCache.IsSagaStateMachineOrDefinition); } AddSagaStateMachines(configurator, types.ToArray()); }
/// <summary> /// Adds SagaStateMachines to the registry, using the factory method, and updates the registrar prior to registering so that the default /// saga registrar isn't notified. /// </summary> /// <param name="configurator"></param> /// <param name="assemblies">The assemblies to scan for state machines</param> public static void AddSagaStateMachines(this IRegistrationConfigurator configurator, params Assembly[] assemblies) { if (assemblies.Length == 0) { assemblies = AppDomain.CurrentDomain.GetAssemblies(); } var types = AssemblyTypeCache.FindTypes(assemblies, type => TypeMetadataCache.IsSagaStateMachineOrDefinition(type) && !TypeMetadataCache.IsFutureOrDefinition(type)) .GetAwaiter().GetResult(); configurator.AddSagaStateMachines(types.FindTypes(TypeClassification.Concrete | TypeClassification.Closed).ToArray()); }