private static IImplementationTypeSelector FromMediatRHandledMessagesInternal(
            ITypeSourceSelector typeSourceSelector, IEnumerable <Type> handlerTypes)
        {
            var handlers = ((IServiceCollectionProvider)typeSourceSelector).ServiceCollection
                           .Select(sd => sd.ServiceType)
                           .Where(t => t.IsGenericType && handlerTypes.Contains(t.GetGenericTypeDefinition()));

            var integrationEventTypes = handlers
                                        .Select(t => t.GetGenericArguments()[0]).ToList();

            var selector = new ImplementationTypeSelector(typeSourceSelector, integrationEventTypes);

            ((IMessageTypeProvider)typeSourceSelector).RegisterTypes(selector);

            return(selector);
        }
Beispiel #2
0
 public ImplementationTypeSelector(ITypeSourceSelector inner, IEnumerable <Type> types)
 {
     _inner = inner;
     _types = types;
 }
Beispiel #3
0
 // Dependency injection for classes
 protected static void ScanAssemblyOf <T>(ITypeSourceSelector source, IServiceCollection services, IEnumerable <(Type LifetimeMarker, ServiceLifetime Lifetime)> markers)
 /// <summary>
 /// Scans the the MediatR IoC registrations for handled queries.
 /// </summary>
 /// <param name="typeSourceSelector">The type source selector.</param>
 /// <returns></returns>
 public static IImplementationTypeSelector FromMediatRHandledQueries(this ITypeSourceSelector typeSourceSelector)
 => FromMediatRHandledMessagesInternal(typeSourceSelector, new[] { queryType });
 /// <summary>
 /// Scans the the MediatR IoC registrations for handled commands.
 /// </summary>
 /// <param name="typeSourceSelector">The type source selector.</param>
 /// <returns></returns>
 public static IImplementationTypeSelector FromMediatRHandledCommands(this ITypeSourceSelector typeSourceSelector)
 => FromMediatRHandledMessagesInternal(typeSourceSelector, new[] { commandType });
Beispiel #6
0
 private void ConfigureScanner(ITypeSourceSelector typeSelector)
 {
     typeSelector.FromAssemblyOf <ServiceRegistration>()
     .AddClasses()
     .AsImplementedInterfaces();
 }