Exemplo n.º 1
0
        /// <summary>
        /// Add ConveyR services to DI container
        /// </summary>
        /// <param name="services"></param>
        /// <param name="assemblies">Assemblies to scan for handlers IProcessHandler</param>
        /// <param name="configuration">custom configuration</param>
        /// <returns></returns>
        public static IServiceCollection AddConveyR(this IServiceCollection services,
                                                    IEnumerable <Assembly> assemblies, Action <ConveyRServiceConfiguration> configuration)
        {
            var conf = new ConveyRServiceConfiguration();

            conf.Using <Conveyor>().AsTransient();

            configuration.Invoke(conf);

            services.AddTransient <ServiceFactory>(p => p.GetServicesByContext);

            assemblies = (assemblies as Assembly[] ?? assemblies).Distinct().ToArray();
            IList <Type> handlerTypes = new List <Type>();

            foreach (var assembly in assemblies)
            {
                foreach (var typeInfo in SearchHandlerTypes(assembly))
                {
                    handlerTypes.Add(typeInfo);
                    services.AddTransient(typeInfo);
                }
            }

            ServiceFactoryExtensions.SetHandlerTypes(handlerTypes);

            services.Add(new ServiceDescriptor(typeof(IConveyor), conf.ConveyorImplementationType, conf.Lifetime));
            return(services);
        }
Exemplo n.º 2
0
 private static IEnumerable <object> GetServicesByContext(this IServiceProvider serviceProvider, Type contextType, Type entityType,
                                                          Type payloadType = null, string processCase = null)
 {
     foreach (var processServiceType in ServiceFactoryExtensions.GetProcessServiceTypes(contextType, entityType, payloadType, processCase))
     {
         yield return(serviceProvider.GetService(processServiceType));
     }
 }