public async Task Handle(AssemblyLoadedEvent e)
        {
            if ((e.Purpose & AssemblyPurpose.Handlers) > 0)
            {
                var handlers = e.Assembly.GetExportedTypes()
                               .Select(x => new
                {
                    ServiceType = x,
                    ImplementedCommandHandlers = x.GetInterfaces()
                                                 .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICommandHandler <,>)),
                    ImplementedQueryHandlers = x.GetInterfaces()
                                               .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IQueryHandler <,>))
                }).ToArray();
                foreach (var h in handlers)
                {
                    foreach (var i in h.ImplementedCommandHandlers)
                    {
                        _commandHandlerRegister.Register(i.GetGenericArguments()[0], h.ServiceType);
                    }

                    foreach (var i in h.ImplementedQueryHandlers)
                    {
                        _queryHandlerRegister.Register(i.GetGenericArguments()[0], h.ServiceType);
                    }
                }
            }
        }
Пример #2
0
 public static void DoBootstrap(IQueryHandlerRegister queryHandlerRegister, IServiceProvider serviceProvider)
 {
     queryHandlerRegister?.Register(() => serviceProvider.GetRequiredService <IQueryHandler <TeamByIdQuery, ReadModels.Team> >());
 }