예제 #1
0
        /// <summary>
        /// Registers handlers and Queue types from the specified assemblies
        /// </summary>
        /// <param name="services">Service collection</param>
        /// <param name="assemblies">Assemblies to scan</param>
        /// <param name="configuration">The action used to configure the options</param>
        /// <returns>Service collection</returns>
        public static IServiceCollection AddMemoryQueue(this IServiceCollection services, IEnumerable <Assembly> assemblies, Action <MemoryQueueServiceConfiguration> configuration)
        {
            if (!assemblies.Any())
            {
                throw new ArgumentException("No assemblies found to scan. Supply at least one assembly to scan for handlers.");
            }
            var serviceConfig = new MemoryQueueServiceConfiguration();

            configuration?.Invoke(serviceConfig);

            ServiceRegistrar.AddRequiredServices(services, serviceConfig);

            ServiceRegistrar.AddMemoryQueueClasses(services, assemblies);

            return(services);
        }
예제 #2
0
 public static void AddRequiredServices(IServiceCollection services, MemoryQueueServiceConfiguration serviceConfiguration)
 {
     services.AddTransient <ServiceFactory>(p => p.GetService);
     services.Add(new ServiceDescriptor(typeof(IMessageQueue), serviceConfiguration.QueueImplementationType, serviceConfiguration.Lifetime));
 }